]> git.saurik.com Git - wxWidgets.git/blame - interface/dnd.h
compilation fix for PCH-less build
[wxWidgets.git] / interface / 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$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxTextDropTarget
11 @wxheader{dnd.h}
7c913512 12
23324ae1 13 A predefined drop target for dealing with text data.
7c913512 14
23324ae1
FM
15 @library{wxcore}
16 @category{dnd}
7c913512 17
bc85d676 18 @see @ref overview_dnd, wxDropSource, wxDropTarget, wxFileDropTarget
23324ae1
FM
19*/
20class wxTextDropTarget : public wxDropTarget
21{
22public:
23 /**
24 Constructor.
25 */
26 wxTextDropTarget();
27
28 /**
bc85d676
BP
29 See wxDropTarget::OnDrop(). This function is implemented appropriately
30 for text, and calls OnDropText().
23324ae1
FM
31 */
32 virtual bool OnDrop(long x, long y, const void data, size_t size);
33
34 /**
35 Override this function to receive dropped text.
3c4f71cc 36
7c913512 37 @param x
4cc4bfaf 38 The x coordinate of the mouse.
7c913512 39 @param y
4cc4bfaf 40 The y coordinate of the mouse.
7c913512 41 @param data
4cc4bfaf 42 The data being dropped: a wxString.
bc85d676
BP
43
44 Return @true to accept the data, or @false to veto the operation.
23324ae1 45 */
bc85d676 46 virtual bool OnDropText(wxCoord x, wxCoord y, const wxString& data);
23324ae1
FM
47};
48
49
e54c96f1 50
bc85d676
BP
51/**
52 Result returned from a wxDropSource::DoDragDrop() call.
53*/
54enum wxDragResult
55{
56 wxDragError, ///< Error prevented the D&D operation from completing.
57 wxDragNone, ///< Drag target didn't accept the data.
58 wxDragCopy, ///< The data was successfully copied.
59 wxDragMove, ///< The data was successfully moved (MSW only).
60 wxDragLink, ///< Operation is a drag-link.
61 wxDragCancel ///< The operation was cancelled by user (not an error).
62};
63
23324ae1
FM
64/**
65 @class wxDropTarget
66 @wxheader{dnd.h}
7c913512 67
bc85d676
BP
68 This class represents a target for a drag and drop operation. A
69 wxDataObject can be associated with it and by default, this object will be
70 filled with the data from the drag source, if the data formats supported by
71 the data object match the drag source data format.
72
73 There are various virtual handler functions defined in this class which may
74 be overridden to give visual feedback or react in a more fine-tuned way,
75 e.g. by not accepting data on the whole window area, but only a small
76 portion of it. The normal sequence of calls is OnEnter(), OnDragOver()
77 possibly many times, OnDrop() and finally OnData().
7c913512 78
23324ae1
FM
79 @library{wxcore}
80 @category{dnd}
7c913512 81
bc85d676
BP
82 @see @ref overview_dnd, @ref overview_dataobject, wxDropSource,
83 wxTextDropTarget, wxFileDropTarget, wxDataFormat, wxDataObject
23324ae1 84*/
7c913512 85class wxDropTarget
23324ae1
FM
86{
87public:
88 /**
4cc4bfaf 89 Constructor. @a data is the data to be associated with the drop target.
23324ae1 90 */
4cc4bfaf 91 wxDropTarget(wxDataObject* data = NULL);
23324ae1
FM
92
93 /**
94 Destructor. Deletes the associated data object, if any.
95 */
96 ~wxDropTarget();
97
98 /**
bc85d676
BP
99 This method may only be called from within OnData(). By default, this
100 method copies the data from the drop source to the wxDataObject
101 associated with this drop target, calling its wxDataObject::SetData()
102 method.
23324ae1
FM
103 */
104 virtual void GetData();
105
106 /**
bc85d676
BP
107 Called after OnDrop() returns @true. By default this will usually
108 GetData() and will return the suggested default value @a def.
23324ae1 109 */
bc85d676 110 virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def);
23324ae1
FM
111
112 /**
bc85d676
BP
113 Called when the mouse is being dragged over the drop target. By
114 default, this calls functions return the suggested return value @a def.
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.
7c913512 120 @param def
bc85d676
BP
121 Suggested value 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 */
bc85d676 128 virtual wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
23324ae1
FM
129
130 /**
bc85d676
BP
131 Called when the user drops a data object on the target. Return @false
132 to veto the operation.
3c4f71cc 133
7c913512 134 @param x
4cc4bfaf 135 The x coordinate of the mouse.
7c913512 136 @param y
4cc4bfaf 137 The y coordinate of the mouse.
3c4f71cc 138
d29a9a8a 139 @return @true to accept the data, or @false to veto the operation.
23324ae1
FM
140 */
141 virtual bool OnDrop(wxCoord x, wxCoord y);
142
143 /**
144 Called when the mouse enters the drop target. By default, this calls
145 OnDragOver().
3c4f71cc 146
7c913512 147 @param x
4cc4bfaf 148 The x coordinate of the mouse.
7c913512 149 @param y
4cc4bfaf 150 The y coordinate of the mouse.
7c913512 151 @param def
bc85d676
BP
152 Suggested default for return value. Determined by SHIFT or CONTROL
153 key states.
3c4f71cc 154
d29a9a8a 155 @return The desired operation or wxDragNone. This is used for optical
bc85d676
BP
156 feedback from the side of the drop source, typically in form
157 of changing the icon.
23324ae1 158 */
bc85d676 159 virtual wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def);
23324ae1
FM
160
161 /**
162 Called when the mouse leaves the drop target.
163 */
164 virtual void OnLeave();
165
166 /**
bc85d676
BP
167 Sets the data wxDataObject associated with the drop target and deletes
168 any previously associated data object.
23324ae1
FM
169 */
170 void SetDataObject(wxDataObject* data);
171};
172
173
e54c96f1 174
23324ae1
FM
175/**
176 @class wxDropSource
177 @wxheader{dnd.h}
7c913512 178
23324ae1 179 This class represents a source for a drag and drop operation.
7c913512 180
23324ae1
FM
181 @library{wxcore}
182 @category{dnd}
7c913512 183
bc85d676
BP
184 @see @ref overview_dnd, @ref overview_dataobject, wxDropTarget,
185 wxTextDropTarget, wxFileDropTarget
23324ae1 186*/
7c913512 187class wxDropSource
23324ae1
FM
188{
189public:
23324ae1 190 /**
bc85d676
BP
191 This constructor requires that you must call SetData() later.
192
193 Note that the exact type of @a iconCopy and subsequent parameters
194 differs between wxMSW and wxGTK: these are cursors under Windows but
195 icons for GTK. You should use the macro wxDROP_ICON() in portable
23324ae1 196 programs instead of directly using either of these types.
3c4f71cc 197
7c913512 198 @param win
4cc4bfaf 199 The window which initiates the drag and drop operation.
7c913512 200 @param iconCopy
4cc4bfaf 201 The icon or cursor used for feedback for copy operation.
7c913512 202 @param iconMove
4cc4bfaf 203 The icon or cursor used for feedback for move operation.
7c913512 204 @param iconNone
4cc4bfaf 205 The icon or cursor used for feedback when operation can't be done.
23324ae1 206 */
4cc4bfaf 207 wxDropSource(wxWindow* win = NULL,
23324ae1
FM
208 const wxIconOrCursor& iconCopy = wxNullIconOrCursor,
209 const wxIconOrCursor& iconMove = wxNullIconOrCursor,
210 const wxIconOrCursor& iconNone = wxNullIconOrCursor);
bc85d676
BP
211 /**
212 Note that the exact type of @a iconCopy and subsequent parameters
213 differs between wxMSW and wxGTK: these are cursors under Windows but
214 icons for GTK. You should use the macro wxDROP_ICON() in portable
215 programs instead of directly using either of these types.
216
217 @param win
218 The window which initiates the drag and drop operation.
219 @param iconCopy
220 The icon or cursor used for feedback for copy operation.
221 @param iconMove
222 The icon or cursor used for feedback for move operation.
223 @param iconNone
224 The icon or cursor used for feedback when operation can't be done.
225 */
4cc4bfaf 226 wxDropSource(wxDataObject& data, wxWindow* win = NULL,
7c913512
FM
227 const wxIconOrCursor& iconCopy = wxNullIconOrCursor,
228 const wxIconOrCursor& iconMove = wxNullIconOrCursor,
229 const wxIconOrCursor& iconNone = wxNullIconOrCursor);
23324ae1
FM
230
231 /**
bc85d676 232 Default constructor.
23324ae1
FM
233 */
234 ~wxDropSource();
235
236 /**
bc85d676
BP
237 Starts the drag-and-drop operation which will terminate when the user
238 releases the mouse. Call this in response to a mouse button press, for
239 example.
3c4f71cc 240
7c913512 241 @param flags
bc85d676
BP
242 If wxDrag_AllowMove is included in the flags, data may be moved and
243 not only copied (default). If wxDrag_DefaultMove is specified
244 (which includes the previous flag), this is even the default
245 operation.
3c4f71cc 246
d29a9a8a 247 @return The operation requested by the user, may be ::wxDragCopy,
bc85d676 248 ::wxDragMove, ::wxDragLink, ::wxDragCancel or ::wxDragNone if
4cc4bfaf 249 an error occurred.
23324ae1
FM
250 */
251 virtual wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly);
252
253 /**
254 Returns the wxDataObject object that has been assigned previously.
255 */
4cc4bfaf 256 wxDataObject* GetDataObject();
23324ae1
FM
257
258 /**
bc85d676
BP
259 You may give some custom UI feedback during the drag and drop operation
260 by overriding this function. It is called on each mouse move, so your
261 implementation must not be too slow.
3c4f71cc 262
7c913512 263 @param effect
bc85d676
BP
264 The effect to implement. One of ::wxDragCopy, ::wxDragMove,
265 ::wxDragLink and ::wxDragNone.
7c913512 266 @param scrolling
4cc4bfaf 267 @true if the window is scrolling. MSW only.
3c4f71cc 268
d29a9a8a 269 @return @false if you want default feedback, or @true if you implement
bc85d676 270 your own feedback. The return values is ignored under GTK.
23324ae1
FM
271 */
272 virtual bool GiveFeedback(wxDragResult effect);
273
274 /**
275 Set the icon to use for a certain drag result.
3c4f71cc 276
7c913512 277 @param res
4cc4bfaf 278 The drag result to set the icon for.
7c913512 279 @param cursor
4cc4bfaf 280 The ion to show when this drag result occurs.
23324ae1
FM
281 */
282 void SetCursor(wxDragResult res, const wxCursor& cursor);
283
284 /**
bc85d676
BP
285 Sets the data wxDataObject associated with the drop source. This will
286 not delete any previously associated data.
23324ae1
FM
287 */
288 void SetData(wxDataObject& data);
289};
290
291
e54c96f1 292
23324ae1
FM
293/**
294 @class wxFileDropTarget
295 @wxheader{dnd.h}
7c913512 296
bc85d676
BP
297 This is a drop target which accepts files (dragged from File Manager or
298 Explorer).
7c913512 299
23324ae1
FM
300 @library{wxcore}
301 @category{dnd}
7c913512 302
bc85d676 303 @see @ref overview_dnd, wxDropSource, wxDropTarget, wxTextDropTarget
23324ae1
FM
304*/
305class wxFileDropTarget : public wxDropTarget
306{
307public:
308 /**
309 Constructor.
310 */
311 wxFileDropTarget();
312
313 /**
bc85d676
BP
314 See wxDropTarget::OnDrop(). This function is implemented appropriately
315 for files, and calls OnDropFiles().
23324ae1
FM
316 */
317 virtual bool OnDrop(long x, long y, const void data, size_t size);
318
319 /**
320 Override this function to receive dropped files.
3c4f71cc 321
7c913512 322 @param x
4cc4bfaf 323 The x coordinate of the mouse.
7c913512 324 @param y
4cc4bfaf 325 The y coordinate of the mouse.
7c913512 326 @param filenames
4cc4bfaf 327 An array of filenames.
bc85d676
BP
328
329 Return @true to accept the data, or @false to veto the operation.
23324ae1
FM
330 */
331 virtual bool OnDropFiles(wxCoord x, wxCoord y,
332 const wxArrayString& filenames);
333};
334
335
e54c96f1 336
23324ae1
FM
337// ============================================================================
338// Global functions/macros
339// ============================================================================
340
a055a116
BP
341/** @ingroup group_funcmacro_gdi */
342//@{
343
23324ae1 344/**
a055a116
BP
345 This macro creates either a cursor (MSW) or an icon (elsewhere) with the
346 given @a name (of type <tt>const char*</tt>). Under MSW, the cursor is
347 loaded from the resource file and the icon is loaded from XPM file under
348 other platforms.
349
350 This macro should be used with wxDropSource::wxDropSource().
351
d29a9a8a 352 @return wxCursor on MSW, otherwise returns a wxIcon
a055a116
BP
353
354 @header{wx/dnd.h}
23324ae1 355*/
a055a116
BP
356#define wxDROP_ICON(name)
357
358//@}
23324ae1 359