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