]>
git.saurik.com Git - wxWidgets.git/blob - interface/dnd.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxTextDropTarget
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxTextDropTarget
13 A predefined drop target for dealing with text data.
18 @see @ref overview_wxdndoverview, wxDropSource, wxDropTarget, wxFileDropTarget
20 class wxTextDropTarget
: public wxDropTarget
29 See wxDropTarget::OnDrop. This function is implemented
30 appropriately for text, and calls OnDropText().
32 virtual bool OnDrop(long x
, long y
, const void data
, size_t size
);
35 Override this function to receive dropped text.
38 The x coordinate of the mouse.
40 The y coordinate of the mouse.
42 The data being dropped: a wxString.
44 virtual bool OnDropText(wxCoord x
, wxCoord y
,
45 const wxString
& data
);
54 This class represents a target for a drag and drop operation. A wxDataObject
55 can be associated with it and by default, this object will be filled with the
57 drag source, if the data formats supported by the data object match the drag
61 There are various virtual handler functions defined in this class which may be
63 to give visual feedback or react in a more fine-tuned way, e.g. by not
65 the whole window area, but only a small portion of it. The normal sequence of
67 wxDropTarget::OnEnter, possibly many times wxDropTarget::OnDragOver,
68 wxDropTarget::OnDrop and finally wxDropTarget::OnData.
70 See @ref overview_wxdndoverview and @ref overview_wxdataobjectoverview
76 @see wxDropSource, wxTextDropTarget, wxFileDropTarget, wxDataFormat,
83 Constructor. @a data is the data to be associated with the drop target.
85 wxDropTarget(wxDataObject
* data
= NULL
);
88 Destructor. Deletes the associated data object, if any.
93 This method may only be called from within OnData().
94 By default, this method copies the data from the drop source to the
95 wxDataObject associated with this drop target,
96 calling its wxDataObject::SetData method.
98 virtual void GetData();
101 Called after OnDrop() returns @true. By default this
102 will usually GetData() and will return the suggested
103 default value @e def.
105 virtual wxDragResult
OnData(wxCoord x
, wxCoord y
,
109 Called when the mouse is being dragged over the drop target. By default,
110 this calls functions return the suggested return value @e def.
113 The x coordinate of the mouse.
115 The y coordinate of the mouse.
117 Suggested value for return value. Determined by SHIFT or CONTROL key states.
119 @returns Returns the desired operation or wxDragNone. This is used for
120 optical feedback from the side of the drop source,
121 typically in form of changing the icon.
123 virtual wxDragResult
OnDragOver(wxCoord x
, wxCoord y
,
127 Called when the user drops a data object on the target. Return @false to veto
131 The x coordinate of the mouse.
133 The y coordinate of the mouse.
135 @returns Return @true to accept the data, @false to veto the operation.
137 virtual bool OnDrop(wxCoord x
, wxCoord y
);
140 Called when the mouse enters the drop target. By default, this calls
144 The x coordinate of the mouse.
146 The y coordinate of the mouse.
148 Suggested default for return value. Determined by SHIFT or CONTROL key
151 @returns Returns the desired operation or wxDragNone. This is used for
152 optical feedback from the side of the drop source,
153 typically in form of changing the icon.
155 virtual wxDragResult
OnEnter(wxCoord x
, wxCoord y
,
159 Called when the mouse leaves the drop target.
161 virtual void OnLeave();
164 Sets the data wxDataObject associated with the
165 drop target and deletes any previously associated data object.
167 void SetDataObject(wxDataObject
* data
);
176 This class represents a source for a drag and drop operation.
178 See @ref overview_wxdndoverview and @ref overview_wxdataobjectoverview
179 for more information.
184 @see wxDropTarget, wxTextDropTarget, wxFileDropTarget
191 The constructors for wxDataObject.
192 If you use the constructor without @a data parameter you must call
194 Note that the exact type of @a iconCopy and subsequent parameters differs
195 between wxMSW and wxGTK: these are cursors under Windows but icons for GTK.
196 You should use the macro wxDROP_ICON() in portable
197 programs instead of directly using either of these types.
200 The window which initiates the drag and drop operation.
202 The icon or cursor used for feedback for copy operation.
204 The icon or cursor used for feedback for move operation.
206 The icon or cursor used for feedback when operation can't be done.
208 wxDropSource(wxWindow
* win
= NULL
,
209 const wxIconOrCursor
& iconCopy
= wxNullIconOrCursor
,
210 const wxIconOrCursor
& iconMove
= wxNullIconOrCursor
,
211 const wxIconOrCursor
& iconNone
= wxNullIconOrCursor
);
212 wxDropSource(wxDataObject
& data
, wxWindow
* win
= NULL
,
213 const wxIconOrCursor
& iconCopy
= wxNullIconOrCursor
,
214 const wxIconOrCursor
& iconMove
= wxNullIconOrCursor
,
215 const wxIconOrCursor
& iconNone
= wxNullIconOrCursor
);
224 Do it (call this in response to a mouse button press, for example). This starts
225 the drag-and-drop operation which will terminate when the user releases the
229 If wxDrag_AllowMove is included in the flags, data may
230 be moved and not only copied (default). If wxDrag_DefaultMove is
231 specified (which includes the previous flag), this is even the default
234 @returns Returns the operation requested by the user, may be wxDragCopy,
235 wxDragMove, wxDragLink, wxDragCancel or wxDragNone if
238 virtual wxDragResult
DoDragDrop(int flags
= wxDrag_CopyOnly
);
241 Returns the wxDataObject object that has been assigned previously.
243 wxDataObject
* GetDataObject();
246 Overridable: you may give some custom UI feedback during the drag and drop
248 in this function. It is called on each mouse move, so your implementation must
253 The effect to implement. One of wxDragCopy, wxDragMove, wxDragLink and
256 @true if the window is scrolling. MSW only.
258 @returns Return @false if you want default feedback, or @true if you
259 implement your own feedback. The return values is
262 virtual bool GiveFeedback(wxDragResult effect
);
265 Set the icon to use for a certain drag result.
268 The drag result to set the icon for.
270 The ion to show when this drag result occurs.
272 void SetCursor(wxDragResult res
, const wxCursor
& cursor
);
275 Sets the data wxDataObject associated with the
276 drop source. This will not delete any previously associated data.
278 void SetData(wxDataObject
& data
);
284 @class wxFileDropTarget
287 This is a @ref overview_wxdroptarget "drop target" which accepts files (dragged
288 from File Manager or Explorer).
293 @see @ref overview_wxdndoverview, wxDropSource, wxDropTarget, wxTextDropTarget
295 class wxFileDropTarget
: public wxDropTarget
304 See wxDropTarget::OnDrop. This function is implemented
305 appropriately for files, and calls OnDropFiles().
307 virtual bool OnDrop(long x
, long y
, const void data
, size_t size
);
310 Override this function to receive dropped files.
313 The x coordinate of the mouse.
315 The y coordinate of the mouse.
317 An array of filenames.
319 virtual bool OnDropFiles(wxCoord x
, wxCoord y
,
320 const wxArrayString
& filenames
);
325 // ============================================================================
326 // Global functions/macros
327 // ============================================================================
329 /** @ingroup group_funcmacro_gdi */
333 This macro creates either a cursor (MSW) or an icon (elsewhere) with the
334 given @a name (of type <tt>const char*</tt>). Under MSW, the cursor is
335 loaded from the resource file and the icon is loaded from XPM file under
338 This macro should be used with wxDropSource::wxDropSource().
340 @returns wxCursor on MSW, otherwise returns a wxIcon
344 #define wxDROP_ICON(name)