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