]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/dnd.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxDropSource and wx*DropTarget
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
9 Possible flags for drag and drop operations.
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.
19 Result returned from a wxDropSource::DoDragDrop() call.
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).
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.
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().
50 @see @ref overview_dnd, @ref overview_dataobject, wxDropSource,
51 wxTextDropTarget, wxFileDropTarget, wxDataFormat, wxDataObject
57 Constructor. @a data is the data to be associated with the drop target.
59 wxDropTarget(wxDataObject
* data
= NULL
);
62 Destructor. Deletes the associated data object, if any.
64 virtual ~wxDropTarget();
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()
72 virtual bool GetData();
75 Called after OnDrop() returns @true. By default this will usually
76 GetData() and will return the suggested default value @a defResult.
78 virtual wxDragResult
OnData(wxCoord x
, wxCoord y
, wxDragResult defResult
) = 0;
81 Called when the mouse is being dragged over the drop target. By
82 default, this calls functions return the suggested return value @a defResult.
85 The x coordinate of the mouse.
87 The y coordinate of the mouse.
89 Suggested value for return value. Determined by SHIFT or CONTROL
92 @return The desired operation or wxDragNone. This is used for optical
93 feedback from the side of the drop source, typically in form
96 virtual wxDragResult
OnDragOver(wxCoord x
, wxCoord y
, wxDragResult defResult
);
99 Called when the user drops a data object on the target. Return @false
100 to veto the operation.
103 The x coordinate of the mouse.
105 The y coordinate of the mouse.
107 @return @true to accept the data, or @false to veto the operation.
109 virtual bool OnDrop(wxCoord x
, wxCoord y
);
112 Called when the mouse enters the drop target. By default, this calls
116 The x coordinate of the mouse.
118 The y coordinate of the mouse.
120 Suggested default for return value. Determined by SHIFT or CONTROL
123 @return The desired operation or wxDragNone. This is used for optical
124 feedback from the side of the drop source, typically in form
125 of changing the icon.
127 virtual wxDragResult
OnEnter(wxCoord x
, wxCoord y
, wxDragResult defResult
);
130 Called when the mouse leaves the drop target.
132 virtual void OnLeave();
135 Returns the data wxDataObject associated with the drop target
137 wxDataObject
*GetDataObject() const;
140 Sets the data wxDataObject associated with the drop target and deletes
141 any previously associated data object.
143 void SetDataObject(wxDataObject
* data
);
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())
152 void SetDefaultAction(wxDragResult action
);
155 Returns default action for drag and drop or wxDragNone if this not
158 wxDragResult
GetDefaultAction();
167 This class represents a source for a drag and drop operation.
172 @see @ref overview_dnd, @ref overview_dataobject, wxDropTarget,
173 wxTextDropTarget, wxFileDropTarget
179 This constructor requires that you must call SetData() later.
181 Note that the type of @a iconCopy and subsequent parameters
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
184 programs instead of directly using either of these types.
186 @onlyfor{wxmsw,wxosx}
189 The window which initiates the drag and drop operation.
191 The icon or cursor used for feedback for copy operation.
193 The icon or cursor used for feedback for move operation.
195 The icon or cursor used for feedback when operation can't be done.
197 wxDropSource(wxWindow
* win
= NULL
,
198 const wxCursor
& iconCopy
= wxNullCursor
,
199 const wxCursor
& iconMove
= wxNullCursor
,
200 const wxCursor
& iconNone
= wxNullCursor
);
203 The constructor taking a wxDataObject.
205 Note that the type of @a iconCopy and subsequent parameters
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
208 programs instead of directly using either of these types.
210 @onlyfor{wxmsw,wxosx}
213 The data associated with the drop source.
215 The window which initiates the drag and drop operation.
217 The icon or cursor used for feedback for copy operation.
219 The icon or cursor used for feedback for move operation.
221 The icon or cursor used for feedback when operation can't be done.
223 wxDropSource(wxDataObject
& data
, wxWindow
* win
= NULL
,
224 const wxCursor
& iconCopy
= wxNullCursor
,
225 const wxCursor
& iconMove
= wxNullCursor
,
226 const wxCursor
& iconNone
= wxNullCursor
);
229 This constructor requires that you must call SetData() later.
231 This is the wxGTK-specific version of the constructor taking wxIcon
232 instead of wxCursor as the other ports.
237 The window which initiates the drag and drop operation.
239 The icon or cursor used for feedback for copy operation.
241 The icon or cursor used for feedback for move operation.
243 The icon or cursor used for feedback when operation can't be done.
245 wxDropSource(wxWindow
* win
= NULL
,
246 const wxIcon
& iconCopy
= wxNullIcon
,
247 const wxIcon
& iconMove
= wxNullIcon
,
248 const wxIcon
& iconNone
= wxNullIcon
);
251 The constructor taking a wxDataObject.
253 This is the wxGTK-specific version of the constructor taking wxIcon
254 instead of wxCursor as the other ports.
259 The data associated with the drop source.
261 The window which initiates the drag and drop operation.
263 The icon or cursor used for feedback for copy operation.
265 The icon or cursor used for feedback for move operation.
267 The icon or cursor used for feedback when operation can't be done.
269 wxDropSource(wxDataObject
& data
, wxWindow
* win
= NULL
,
270 const wxIcon
& iconCopy
= wxNullIcon
,
271 const wxIcon
& iconMove
= wxNullIcon
,
272 const wxIcon
& iconNone
= wxNullIcon
);
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
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.
286 @return The operation requested by the user, may be ::wxDragCopy,
287 ::wxDragMove, ::wxDragLink, ::wxDragCancel or ::wxDragNone if
290 virtual wxDragResult
DoDragDrop(int flags
= wxDrag_CopyOnly
);
293 Returns the wxDataObject object that has been assigned previously.
295 wxDataObject
* GetDataObject();
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.
303 The effect to implement. One of ::wxDragCopy, ::wxDragMove,
304 ::wxDragLink and ::wxDragNone.
306 @return @false if you want default feedback, or @true if you implement
307 your own feedback. The return value is ignored under GTK.
309 virtual bool GiveFeedback(wxDragResult effect
);
312 Set the icon to use for a certain drag result.
315 The drag result to set the icon for.
317 The icon to show when this drag result occurs.
319 @onlyfor{wxmsw,wxosx}
321 void SetCursor(wxDragResult res
, const wxCursor
& cursor
);
324 Set the icon to use for a certain drag result.
327 The drag result to set the icon for.
329 The icon to show when this drag result occurs.
333 void SetIcon(wxDragResult res
, const wxIcon
& icon
);
336 Sets the data wxDataObject associated with the drop source. This will
337 not delete any previously associated data.
339 void SetData(wxDataObject
& data
);
345 @class wxTextDropTarget
347 A predefined drop target for dealing with text data.
352 @see @ref overview_dnd, wxDropSource, wxDropTarget, wxFileDropTarget
354 class wxTextDropTarget
: public wxDropTarget
363 See wxDropTarget::OnDrop(). This function is implemented appropriately
364 for text, and calls OnDropText().
366 virtual bool OnDrop(wxCoord x
, wxCoord y
);
369 Override this function to receive dropped text.
372 The x coordinate of the mouse.
374 The y coordinate of the mouse.
376 The data being dropped: a wxString.
378 Return @true to accept the data, or @false to veto the operation.
380 virtual bool OnDropText(wxCoord x
, wxCoord y
, const wxString
& data
) = 0;
385 @class wxFileDropTarget
387 This is a drop target which accepts files (dragged from File Manager or
393 @see @ref overview_dnd, wxDropSource, wxDropTarget, wxTextDropTarget
395 class wxFileDropTarget
: public wxDropTarget
404 See wxDropTarget::OnDrop(). This function is implemented appropriately
405 for files, and calls OnDropFiles().
407 virtual bool OnDrop(wxCoord x
, wxCoord y
);
410 Override this function to receive dropped files.
413 The x coordinate of the mouse.
415 The y coordinate of the mouse.
417 An array of filenames.
419 Return @true to accept the data, or @false to veto the operation.
421 virtual bool OnDropFiles(wxCoord x
, wxCoord y
,
422 const wxArrayString
& filenames
) = 0;
427 // ============================================================================
428 // Global functions/macros
429 // ============================================================================
431 /** @addtogroup group_funcmacro_gdi */
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
440 This macro should be used with wxDropSource::wxDropSource().
442 @return wxCursor on MSW, otherwise returns a wxIcon
446 #define wxDROP_ICON(name)
449 Returns true if res indicates that something was done during a DnD operation,
450 i.e. is neither error nor none nor cancel.
452 bool wxIsDragResultOk(wxDragResult res
);