]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/dnd.h
Avoid needless second string conversion when adding files to memory FS.
[wxWidgets.git] / interface / wx / dnd.h
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 /**
10 @class wxTextDropTarget
11
12 A predefined drop target for dealing with text data.
13
14 @library{wxcore}
15 @category{dnd}
16
17 @see @ref overview_dnd, wxDropSource, wxDropTarget, wxFileDropTarget
18 */
19 class wxTextDropTarget : public wxDropTarget
20 {
21 public:
22 /**
23 Constructor.
24 */
25 wxTextDropTarget();
26
27 /**
28 See wxDropTarget::OnDrop(). This function is implemented appropriately
29 for text, and calls OnDropText().
30 */
31 virtual bool OnDrop(wxCoord x, wxCoord y);
32
33 /**
34 Override this function to receive dropped text.
35
36 @param x
37 The x coordinate of the mouse.
38 @param y
39 The y coordinate of the mouse.
40 @param data
41 The data being dropped: a wxString.
42
43 Return @true to accept the data, or @false to veto the operation.
44 */
45 virtual bool OnDropText(wxCoord x, wxCoord y, const wxString& data) = 0;
46 };
47
48
49
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
63 /**
64 @class wxDropTarget
65
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().
76
77 @library{wxcore}
78 @category{dnd}
79
80 @see @ref overview_dnd, @ref overview_dataobject, wxDropSource,
81 wxTextDropTarget, wxFileDropTarget, wxDataFormat, wxDataObject
82 */
83 class wxDropTarget
84 {
85 public:
86 /**
87 Constructor. @a data is the data to be associated with the drop target.
88 */
89 wxDropTarget(wxDataObject* data = NULL);
90
91 /**
92 Destructor. Deletes the associated data object, if any.
93 */
94 virtual ~wxDropTarget();
95
96 /**
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.
101 */
102 virtual bool GetData();
103
104 /**
105 Called after OnDrop() returns @true. By default this will usually
106 GetData() and will return the suggested default value @a def.
107 */
108 virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def);
109
110 /**
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.
113
114 @param x
115 The x coordinate of the mouse.
116 @param y
117 The y coordinate of the mouse.
118 @param def
119 Suggested value for return value. Determined by SHIFT or CONTROL
120 key states.
121
122 @return The desired operation or wxDragNone. This is used for optical
123 feedback from the side of the drop source, typically in form
124 of changing the icon.
125 */
126 virtual wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
127
128 /**
129 Called when the user drops a data object on the target. Return @false
130 to veto the operation.
131
132 @param x
133 The x coordinate of the mouse.
134 @param y
135 The y coordinate of the mouse.
136
137 @return @true to accept the data, or @false to veto the operation.
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().
144
145 @param x
146 The x coordinate of the mouse.
147 @param y
148 The y coordinate of the mouse.
149 @param def
150 Suggested default for return value. Determined by SHIFT or CONTROL
151 key states.
152
153 @return The desired operation or wxDragNone. This is used for optical
154 feedback from the side of the drop source, typically in form
155 of changing the icon.
156 */
157 virtual wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def);
158
159 /**
160 Called when the mouse leaves the drop target.
161 */
162 virtual void OnLeave();
163
164 /**
165 Sets the data wxDataObject associated with the drop target and deletes
166 any previously associated data object.
167 */
168 void SetDataObject(wxDataObject* data);
169 };
170
171
172
173 /**
174 @class wxDropSource
175
176 This class represents a source for a drag and drop operation.
177
178 @library{wxcore}
179 @category{dnd}
180
181 @see @ref overview_dnd, @ref overview_dataobject, wxDropTarget,
182 wxTextDropTarget, wxFileDropTarget
183 */
184 class wxDropSource
185 {
186 public:
187 /**
188 This constructor requires that you must call SetData() later.
189
190 Note that the type of @a iconCopy and subsequent parameters
191 differs between different ports: these are cursors under Windows and OS
192 X but icons for GTK. You should use the macro wxDROP_ICON() in portable
193 programs instead of directly using either of these types.
194
195 @onlyfor{wxmsw,wxosx}
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 wxCursor& iconCopy = wxNullIcon,
208 const wxCursor& iconMove = wxNullIcon,
209 const wxCursor& iconNone = wxNullIcon);
210
211 /**
212 The constructor taking a wxDataObject.
213
214 Note that the type of @a iconCopy and subsequent parameters
215 differs between different ports: these are cursors under Windows and OS
216 X but 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,wxosx}
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 wxCursor& iconCopy = wxNullIcon,
234 const wxCursor& iconMove = wxNullIcon,
235 const wxCursor& iconNone = wxNullIcon);
236
237 /**
238 This constructor requires that you must call SetData() later.
239
240 This is the wxGTK-specific version of the constructor taking wxIcon
241 instead of wxCursor as the other ports.
242
243 @onlyfor{wxgtk}
244
245 @param win
246 The window which initiates the drag and drop operation.
247 @param iconCopy
248 The icon or cursor used for feedback for copy operation.
249 @param iconMove
250 The icon or cursor used for feedback for move operation.
251 @param iconNone
252 The icon or cursor used for feedback when operation can't be done.
253 */
254 wxDropSource(wxWindow* win = NULL,
255 const wxIcon& iconCopy = wxNullCursor,
256 const wxIcon& iconMove = wxNullCursor,
257 const wxIcon& iconNone = wxNullCursor);
258
259 /**
260 The constructor taking a wxDataObject.
261
262 This is the wxGTK-specific version of the constructor taking wxIcon
263 instead of wxCursor as the other ports.
264
265 @onlyfor{wxgtk}
266
267 @param data
268 The data associated with the drop source.
269 @param win
270 The window which initiates the drag and drop operation.
271 @param iconCopy
272 The icon or cursor used for feedback for copy operation.
273 @param iconMove
274 The icon or cursor used for feedback for move operation.
275 @param iconNone
276 The icon or cursor used for feedback when operation can't be done.
277 */
278 wxDropSource(wxDataObject& data, wxWindow* win = NULL,
279 const wxIcon& iconCopy = wxNullCursor,
280 const wxIcon& iconMove = wxNullCursor,
281 const wxIcon& iconNone = wxNullCursor);
282
283 /**
284 Starts the drag-and-drop operation which will terminate when the user
285 releases the mouse. Call this in response to a mouse button press, for
286 example.
287
288 @param flags
289 If wxDrag_AllowMove is included in the flags, data may be moved and
290 not only copied (default). If wxDrag_DefaultMove is specified
291 (which includes the previous flag), this is even the default
292 operation.
293
294 @return The operation requested by the user, may be ::wxDragCopy,
295 ::wxDragMove, ::wxDragLink, ::wxDragCancel or ::wxDragNone if
296 an error occurred.
297 */
298 virtual wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly);
299
300 /**
301 Returns the wxDataObject object that has been assigned previously.
302 */
303 wxDataObject* GetDataObject();
304
305 /**
306 You may give some custom UI feedback during the drag and drop operation
307 by overriding this function. It is called on each mouse move, so your
308 implementation must not be too slow.
309
310 @param effect
311 The effect to implement. One of ::wxDragCopy, ::wxDragMove,
312 ::wxDragLink and ::wxDragNone.
313
314 @return @false if you want default feedback, or @true if you implement
315 your own feedback. The return value is ignored under GTK.
316 */
317 virtual bool GiveFeedback(wxDragResult effect);
318
319 /**
320 Set the icon to use for a certain drag result.
321
322 @param res
323 The drag result to set the icon for.
324 @param cursor
325 The ion to show when this drag result occurs.
326 */
327 void SetCursor(wxDragResult res, const wxCursor& cursor);
328
329 /**
330 Sets the data wxDataObject associated with the drop source. This will
331 not delete any previously associated data.
332 */
333 void SetData(wxDataObject& data);
334 };
335
336
337
338 /**
339 @class wxFileDropTarget
340
341 This is a drop target which accepts files (dragged from File Manager or
342 Explorer).
343
344 @library{wxcore}
345 @category{dnd}
346
347 @see @ref overview_dnd, wxDropSource, wxDropTarget, wxTextDropTarget
348 */
349 class wxFileDropTarget : public wxDropTarget
350 {
351 public:
352 /**
353 Constructor.
354 */
355 wxFileDropTarget();
356
357 /**
358 See wxDropTarget::OnDrop(). This function is implemented appropriately
359 for files, and calls OnDropFiles().
360 */
361 virtual bool OnDrop(wxCoord x, wxCoord y);
362
363 /**
364 Override this function to receive dropped files.
365
366 @param x
367 The x coordinate of the mouse.
368 @param y
369 The y coordinate of the mouse.
370 @param filenames
371 An array of filenames.
372
373 Return @true to accept the data, or @false to veto the operation.
374 */
375 virtual bool OnDropFiles(wxCoord x, wxCoord y,
376 const wxArrayString& filenames) = 0;
377 };
378
379
380
381 // ============================================================================
382 // Global functions/macros
383 // ============================================================================
384
385 /** @addtogroup group_funcmacro_gdi */
386 //@{
387
388 /**
389 This macro creates either a cursor (MSW) or an icon (elsewhere) with the
390 given @a name (of type <tt>const char*</tt>). Under MSW, the cursor is
391 loaded from the resource file and the icon is loaded from XPM file under
392 other platforms.
393
394 This macro should be used with wxDropSource::wxDropSource().
395
396 @return wxCursor on MSW, otherwise returns a wxIcon
397
398 @header{wx/dnd.h}
399 */
400 #define wxDROP_ICON(name)
401
402 //@}
403