]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/dnd.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxDropSource and wx*DropTarget
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 Possible flags for drag and drop operations.
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.
20 Result returned from a wxDropSource::DoDragDrop() call.
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).
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.
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().
51 @see @ref overview_dnd, @ref overview_dataobject, wxDropSource,
52 wxTextDropTarget, wxFileDropTarget, wxDataFormat, wxDataObject
58 Constructor. @a data is the data to be associated with the drop target.
60 wxDropTarget(wxDataObject
* data
= NULL
);
63 Destructor. Deletes the associated data object, if any.
65 virtual ~wxDropTarget();
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()
73 virtual bool GetData();
76 Called after OnDrop() returns @true. By default this will usually
77 GetData() and will return the suggested default value @a defResult.
79 virtual wxDragResult
OnData(wxCoord x
, wxCoord y
, wxDragResult defResult
) = 0;
82 Called when the mouse is being dragged over the drop target. By
83 default, this calls functions return the suggested return value @a defResult.
86 The x coordinate of the mouse.
88 The y coordinate of the mouse.
90 Suggested value for return value. Determined by SHIFT or CONTROL
93 @return The desired operation or wxDragNone. This is used for optical
94 feedback from the side of the drop source, typically in form
97 virtual wxDragResult
OnDragOver(wxCoord x
, wxCoord y
, wxDragResult defResult
);
100 Called when the user drops a data object on the target. Return @false
101 to veto the operation.
104 The x coordinate of the mouse.
106 The y coordinate of the mouse.
108 @return @true to accept the data, or @false to veto the operation.
110 virtual bool OnDrop(wxCoord x
, wxCoord y
);
113 Called when the mouse enters the drop target. By default, this calls
117 The x coordinate of the mouse.
119 The y coordinate of the mouse.
121 Suggested default for return value. Determined by SHIFT or CONTROL
124 @return The desired operation or wxDragNone. This is used for optical
125 feedback from the side of the drop source, typically in form
126 of changing the icon.
128 virtual wxDragResult
OnEnter(wxCoord x
, wxCoord y
, wxDragResult defResult
);
131 Called when the mouse leaves the drop target.
133 virtual void OnLeave();
136 Sets the data wxDataObject associated with the drop target and deletes
137 any previously associated data object.
139 void SetDataObject(wxDataObject
* data
);
143 Sets the default action for drag and drop. Use wxDragMove or
144 wxDragCopy to set deafult action to move or copy and use wxDragNone
145 (default) to set default action specified by initialization of draging
146 (see wxDropSource::DoDragDrop())
148 void SetDefaultAction(wxDragResult action
);
151 Returns default action for drag and drop or wxDragNone if this not
154 wxDragResult
GetDefaultAction();
163 This class represents a source for a drag and drop operation.
168 @see @ref overview_dnd, @ref overview_dataobject, wxDropTarget,
169 wxTextDropTarget, wxFileDropTarget
175 This constructor requires that you must call SetData() later.
177 Note that the type of @a iconCopy and subsequent parameters
178 differs between different ports: these are cursors under Windows and OS
179 X but icons for GTK. You should use the macro wxDROP_ICON() in portable
180 programs instead of directly using either of these types.
182 @onlyfor{wxmsw,wxosx}
185 The window which initiates the drag and drop operation.
187 The icon or cursor used for feedback for copy operation.
189 The icon or cursor used for feedback for move operation.
191 The icon or cursor used for feedback when operation can't be done.
193 wxDropSource(wxWindow
* win
= NULL
,
194 const wxCursor
& iconCopy
= wxNullCursor
,
195 const wxCursor
& iconMove
= wxNullCursor
,
196 const wxCursor
& iconNone
= wxNullCursor
);
199 The constructor taking a wxDataObject.
201 Note that the type of @a iconCopy and subsequent parameters
202 differs between different ports: these are cursors under Windows and OS
203 X but icons for GTK. You should use the macro wxDROP_ICON() in portable
204 programs instead of directly using either of these types.
206 @onlyfor{wxmsw,wxosx}
209 The data associated with the drop source.
211 The window which initiates the drag and drop operation.
213 The icon or cursor used for feedback for copy operation.
215 The icon or cursor used for feedback for move operation.
217 The icon or cursor used for feedback when operation can't be done.
219 wxDropSource(wxDataObject
& data
, wxWindow
* win
= NULL
,
220 const wxCursor
& iconCopy
= wxNullCursor
,
221 const wxCursor
& iconMove
= wxNullCursor
,
222 const wxCursor
& iconNone
= wxNullCursor
);
225 This constructor requires that you must call SetData() later.
227 This is the wxGTK-specific version of the constructor taking wxIcon
228 instead of wxCursor as the other ports.
233 The window which initiates the drag and drop operation.
235 The icon or cursor used for feedback for copy operation.
237 The icon or cursor used for feedback for move operation.
239 The icon or cursor used for feedback when operation can't be done.
241 wxDropSource(wxWindow
* win
= NULL
,
242 const wxIcon
& iconCopy
= wxNullIcon
,
243 const wxIcon
& iconMove
= wxNullIcon
,
244 const wxIcon
& iconNone
= wxNullIcon
);
247 The constructor taking a wxDataObject.
249 This is the wxGTK-specific version of the constructor taking wxIcon
250 instead of wxCursor as the other ports.
255 The data associated with the drop source.
257 The window which initiates the drag and drop operation.
259 The icon or cursor used for feedback for copy operation.
261 The icon or cursor used for feedback for move operation.
263 The icon or cursor used for feedback when operation can't be done.
265 wxDropSource(wxDataObject
& data
, wxWindow
* win
= NULL
,
266 const wxIcon
& iconCopy
= wxNullIcon
,
267 const wxIcon
& iconMove
= wxNullIcon
,
268 const wxIcon
& iconNone
= wxNullIcon
);
271 Starts the drag-and-drop operation which will terminate when the user
272 releases the mouse. Call this in response to a mouse button press, for
276 If ::wxDrag_AllowMove is included in the flags, data may be moved
277 and not only copied as is the case for the default
278 ::wxDrag_CopyOnly. If ::wxDrag_DefaultMove is specified
279 (which includes the previous flag), moving is not only possible but
280 becomes the default operation.
282 @return The operation requested by the user, may be ::wxDragCopy,
283 ::wxDragMove, ::wxDragLink, ::wxDragCancel or ::wxDragNone if
286 virtual wxDragResult
DoDragDrop(int flags
= wxDrag_CopyOnly
);
289 Returns the wxDataObject object that has been assigned previously.
291 wxDataObject
* GetDataObject();
294 You may give some custom UI feedback during the drag and drop operation
295 by overriding this function. It is called on each mouse move, so your
296 implementation must not be too slow.
299 The effect to implement. One of ::wxDragCopy, ::wxDragMove,
300 ::wxDragLink and ::wxDragNone.
302 @return @false if you want default feedback, or @true if you implement
303 your own feedback. The return value is ignored under GTK.
305 virtual bool GiveFeedback(wxDragResult effect
);
308 Set the icon to use for a certain drag result.
311 The drag result to set the icon for.
313 The icon to show when this drag result occurs.
315 @onlyfor{wxmsw,wxosx}
317 void SetCursor(wxDragResult res
, const wxCursor
& cursor
);
320 Set the icon to use for a certain drag result.
323 The drag result to set the icon for.
325 The icon to show when this drag result occurs.
329 void SetIcon(wxDragResult res
, const wxIcon
& icon
);
332 Sets the data wxDataObject associated with the drop source. This will
333 not delete any previously associated data.
335 void SetData(wxDataObject
& data
);
341 @class wxTextDropTarget
343 A predefined drop target for dealing with text data.
348 @see @ref overview_dnd, wxDropSource, wxDropTarget, wxFileDropTarget
350 class wxTextDropTarget
: public wxDropTarget
359 See wxDropTarget::OnDrop(). This function is implemented appropriately
360 for text, and calls OnDropText().
362 virtual bool OnDrop(wxCoord x
, wxCoord y
);
365 Override this function to receive dropped text.
368 The x coordinate of the mouse.
370 The y coordinate of the mouse.
372 The data being dropped: a wxString.
374 Return @true to accept the data, or @false to veto the operation.
376 virtual bool OnDropText(wxCoord x
, wxCoord y
, const wxString
& data
) = 0;
381 @class wxFileDropTarget
383 This is a drop target which accepts files (dragged from File Manager or
389 @see @ref overview_dnd, wxDropSource, wxDropTarget, wxTextDropTarget
391 class wxFileDropTarget
: public wxDropTarget
400 See wxDropTarget::OnDrop(). This function is implemented appropriately
401 for files, and calls OnDropFiles().
403 virtual bool OnDrop(wxCoord x
, wxCoord y
);
406 Override this function to receive dropped files.
409 The x coordinate of the mouse.
411 The y coordinate of the mouse.
413 An array of filenames.
415 Return @true to accept the data, or @false to veto the operation.
417 virtual bool OnDropFiles(wxCoord x
, wxCoord y
,
418 const wxArrayString
& filenames
) = 0;
423 // ============================================================================
424 // Global functions/macros
425 // ============================================================================
427 /** @addtogroup group_funcmacro_gdi */
431 This macro creates either a cursor (MSW) or an icon (elsewhere) with the
432 given @a name (of type <tt>const char*</tt>). Under MSW, the cursor is
433 loaded from the resource file and the icon is loaded from XPM file under
436 This macro should be used with wxDropSource::wxDropSource().
438 @return wxCursor on MSW, otherwise returns a wxIcon
442 #define wxDROP_ICON(name)
445 Returns true if res indicates that something was done during a DnD operation,
446 i.e. is neither error nor none nor cancel.
448 bool wxIsDragResultOk(wxDragResult res
);