]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dataobj.h | |
3 | // Purpose: documentation for wxCustomDataObject class | |
4 | // Author: wxWidgets team | |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxCustomDataObject | |
11 | @wxheader{dataobj.h} | |
7c913512 FM |
12 | |
13 | wxCustomDataObject is a specialization of | |
23324ae1 FM |
14 | wxDataObjectSimple for some |
15 | application-specific data in arbitrary (either custom or one of the standard | |
16 | ones). The only restriction is that it is supposed that this data can be | |
17 | copied bitwise (i.e. with @c memcpy()), so it would be a bad idea to make | |
18 | it contain a C++ object (though C struct is fine). | |
7c913512 | 19 | |
23324ae1 | 20 | By default, wxCustomDataObject stores the data inside in a buffer. To put the |
7c913512 FM |
21 | data into the buffer you may use either |
22 | wxCustomDataObject::SetData or | |
23324ae1 FM |
23 | wxCustomDataObject::TakeData depending on whether you want |
24 | the object to make a copy of data or not. | |
7c913512 | 25 | |
23324ae1 FM |
26 | If you already store the data in another place, it may be more convenient and |
27 | efficient to provide the data on-demand which is possible too if you override | |
28 | the virtual functions mentioned below. | |
7c913512 | 29 | |
23324ae1 FM |
30 | @library{wxcore} |
31 | @category{dnd} | |
7c913512 | 32 | |
23324ae1 FM |
33 | @seealso |
34 | wxDataObject | |
35 | */ | |
36 | class wxCustomDataObject : public wxDataObjectSimple | |
37 | { | |
38 | public: | |
39 | /** | |
40 | The constructor accepts a @e format argument which specifies the (single) | |
7c913512 | 41 | format supported by this object. If it isn't set here, |
23324ae1 FM |
42 | wxDataObjectSimple::SetFormat should be used. |
43 | */ | |
44 | wxCustomDataObject(const wxDataFormat& format = wxFormatInvalid); | |
45 | ||
46 | /** | |
47 | The destructor will free the data hold by the object. Notice that although it | |
48 | calls a virtual Free() function, the base | |
49 | class version will always be called (C++ doesn't allow calling virtual | |
50 | functions from constructors or destructors), so if you override @c Free(), you | |
51 | should override the destructor in your class as well (which would probably | |
52 | just call the derived class' version of @c Free()). | |
53 | */ | |
54 | ~wxCustomDataObject(); | |
55 | ||
56 | /** | |
57 | This function is called to allocate @e size bytes of memory from SetData(). | |
58 | The default version just uses the operator new. | |
59 | */ | |
60 | virtual void * Alloc(size_t size); | |
61 | ||
62 | /** | |
63 | This function is called when the data is freed, you may override it to anything | |
64 | you want (or may be nothing at all). The default version calls operator | |
65 | delete[] on the data. | |
66 | */ | |
67 | virtual void Free(); | |
68 | ||
69 | /** | |
70 | Returns a pointer to the data. | |
71 | */ | |
72 | virtual void * GetData(); | |
73 | ||
74 | /** | |
75 | Returns the data size in bytes. | |
76 | */ | |
77 | virtual size_t GetSize(); | |
78 | ||
79 | /** | |
80 | Set the data. The data object will make an internal copy. | |
81 | */ | |
82 | virtual void SetData(size_t size, const void data); | |
83 | ||
84 | /** | |
85 | Like SetData(), but doesn't copy the data - | |
86 | instead the object takes ownership of the pointer. | |
87 | ||
88 | @b wxPython note: This method expects a string in wxPython. You can pass | |
89 | nearly any object by pickling it first. | |
90 | */ | |
91 | virtual void TakeData(size_t size, const void data); | |
92 | }; | |
93 | ||
94 | ||
95 | /** | |
96 | @class wxDataObjectComposite | |
97 | @wxheader{dataobj.h} | |
7c913512 FM |
98 | |
99 | wxDataObjectComposite is the simplest | |
23324ae1 | 100 | wxDataObject derivation which may be used to support |
7c913512 | 101 | multiple formats. It contains several |
23324ae1 FM |
102 | wxDataObjectSimple objects and supports any |
103 | format supported by at least one of them. Only one of these data objects is | |
104 | @e preferred (the first one if not explicitly changed by using the second | |
105 | parameter of wxDataObjectComposite::Add) and its format determines | |
106 | the preferred format of the composite data object as well. | |
7c913512 | 107 | |
23324ae1 FM |
108 | See wxDataObject documentation for the reasons why you |
109 | might prefer to use wxDataObject directly instead of wxDataObjectComposite for | |
110 | efficiency reasons. | |
7c913512 | 111 | |
23324ae1 FM |
112 | @library{wxcore} |
113 | @category{FIXME} | |
7c913512 | 114 | |
23324ae1 FM |
115 | @seealso |
116 | @ref overview_wxdndoverview "Clipboard and drag and drop overview", | |
117 | wxDataObject, wxDataObjectSimple, wxFileDataObject, wxTextDataObject, wxBitmapDataObject | |
118 | */ | |
119 | class wxDataObjectComposite : public wxDataObject | |
120 | { | |
121 | public: | |
122 | /** | |
123 | The default constructor. | |
124 | */ | |
125 | wxDataObjectComposite(); | |
126 | ||
127 | /** | |
128 | Adds the @e dataObject to the list of supported objects and it becomes the | |
129 | preferred object if @e preferred is @true. | |
130 | */ | |
131 | #define void Add(wxDataObjectSimple dataObject, bool preferred = @false) /* implementation is private */ | |
132 | ||
133 | /** | |
134 | Report the format passed to the SetData method. This should be the | |
135 | format of the data object within the composite that recieved data from | |
136 | the clipboard or the DnD operation. You can use this method to find | |
137 | out what kind of data object was recieved. | |
138 | */ | |
139 | wxDataFormat GetReceivedFormat(); | |
140 | }; | |
141 | ||
142 | ||
143 | /** | |
144 | @class wxDataObjectSimple | |
145 | @wxheader{dataobj.h} | |
7c913512 FM |
146 | |
147 | This is the simplest possible implementation of the | |
23324ae1 FM |
148 | wxDataObject class. The data object of (a class derived |
149 | from) this class only supports one format, so the number of virtual functions | |
150 | to be implemented is reduced. | |
7c913512 | 151 | |
23324ae1 FM |
152 | Notice that this is still an abstract base class and cannot be used but should |
153 | be derived from. | |
7c913512 | 154 | |
23324ae1 FM |
155 | @b wxPython note: If you wish to create a derived wxDataObjectSimple class in |
156 | wxPython you should derive the class from wxPyDataObjectSimple | |
157 | in order to get Python-aware capabilities for the various virtual | |
158 | methods. | |
7c913512 | 159 | |
23324ae1 FM |
160 | @b wxPerl note: In wxPerl, you need to derive your data object class |
161 | from Wx::PlDataObjectSimple. | |
7c913512 | 162 | |
23324ae1 FM |
163 | @library{wxcore} |
164 | @category{FIXME} | |
7c913512 | 165 | |
23324ae1 FM |
166 | @seealso |
167 | @ref overview_wxdndoverview "Clipboard and drag and drop overview", @ref | |
168 | overview_samplednd "DnD sample", wxFileDataObject, wxTextDataObject, wxBitmapDataObject | |
169 | */ | |
170 | class wxDataObjectSimple : public wxDataObject | |
171 | { | |
172 | public: | |
173 | /** | |
174 | Constructor accepts the supported format (none by default) which may also be | |
175 | set later with SetFormat(). | |
176 | */ | |
177 | wxDataObjectSimple(const wxDataFormat& format = wxFormatInvalid); | |
178 | ||
179 | /** | |
180 | Copy the data to the buffer, return @true on success. Must be implemented in the | |
181 | derived class if the object supports rendering its data. | |
182 | */ | |
183 | virtual bool GetDataHere(void buf); | |
184 | ||
185 | /** | |
186 | Gets the size of our data. Must be implemented in the derived class if the | |
187 | object supports rendering its data. | |
188 | */ | |
189 | virtual size_t GetDataSize(); | |
190 | ||
191 | /** | |
192 | Returns the (one and only one) format supported by this object. It is supposed | |
193 | that the format is supported in both directions. | |
194 | */ | |
195 | const wxDataFormat GetFormat(); | |
196 | ||
197 | /** | |
198 | Copy the data from the buffer, return @true on success. Must be implemented in | |
199 | the derived class if the object supports setting its data. | |
200 | ||
201 | @b wxPython note: When implementing this method in wxPython, the data comes | |
202 | as a single string parameter rather than the two shown here. | |
203 | */ | |
204 | virtual bool SetData(size_t len, const void buf); | |
205 | ||
206 | /** | |
207 | Sets the supported format. | |
208 | */ | |
209 | void SetFormat(const wxDataFormat& format); | |
210 | }; | |
211 | ||
212 | ||
213 | /** | |
214 | @class wxBitmapDataObject | |
215 | @wxheader{dataobj.h} | |
7c913512 | 216 | |
23324ae1 | 217 | wxBitmapDataObject is a specialization of wxDataObject for bitmap data. It can |
7c913512 | 218 | be used without change to paste data into the |
23324ae1 FM |
219 | wxClipboard or a wxDropSource. A |
220 | user may wish to derive a new class from this class for providing a bitmap | |
221 | on-demand in order to minimize memory consumption when offering data in several | |
222 | formats, such as a bitmap and GIF. | |
7c913512 | 223 | |
23324ae1 FM |
224 | @b wxPython note: If you wish to create a derived wxBitmapDataObject class in |
225 | wxPython you should derive the class from wxPyBitmapDataObject | |
226 | in order to get Python-aware capabilities for the various virtual | |
227 | methods. | |
7c913512 | 228 | |
23324ae1 FM |
229 | @library{wxcore} |
230 | @category{dnd} | |
7c913512 | 231 | |
23324ae1 FM |
232 | @seealso |
233 | @ref overview_wxdndoverview "Clipboard and drag and drop overview", | |
234 | wxDataObject, wxDataObjectSimple, wxFileDataObject, wxTextDataObject, wxDataObject | |
235 | */ | |
236 | class wxBitmapDataObject : public wxDataObjectSimple | |
237 | { | |
238 | public: | |
239 | /** | |
7c913512 | 240 | Constructor, optionally passing a bitmap (otherwise use |
23324ae1 FM |
241 | SetBitmap() later). |
242 | */ | |
243 | wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap); | |
244 | ||
245 | /** | |
246 | Returns the bitmap associated with the data object. You may wish to override | |
247 | this method when offering data on-demand, but this is not required by | |
248 | wxWidgets' internals. Use this method to get data in bitmap form from | |
249 | the wxClipboard. | |
250 | */ | |
251 | virtual wxBitmap GetBitmap(); | |
252 | ||
253 | /** | |
254 | Sets the bitmap associated with the data object. This method is called when the | |
255 | data object receives data. Usually there will be no reason to override this | |
256 | function. | |
257 | */ | |
258 | virtual void SetBitmap(const wxBitmap& bitmap); | |
259 | }; | |
260 | ||
261 | ||
262 | /** | |
263 | @class wxDataFormat | |
264 | @wxheader{dataobj.h} | |
7c913512 | 265 | |
23324ae1 FM |
266 | A wxDataFormat is an encapsulation of a platform-specific format handle which |
267 | is used by the system for the clipboard and drag and drop operations. The | |
268 | applications are usually only interested in, for example, pasting data from the | |
269 | clipboard only if the data is in a format the program understands and a data | |
270 | format is something which uniquely identifies this format. | |
7c913512 | 271 | |
23324ae1 FM |
272 | On the system level, a data format is usually just a number (@c CLIPFORMAT |
273 | under Windows or @c Atom under X11, for example) and the standard formats | |
274 | are, indeed, just numbers which can be implicitly converted to wxDataFormat. | |
275 | The standard formats are: | |
7c913512 FM |
276 | |
277 | ||
278 | ||
23324ae1 | 279 | wxDF_INVALID |
7c913512 FM |
280 | |
281 | ||
23324ae1 FM |
282 | An invalid format - used as default argument for |
283 | functions taking a wxDataFormat argument sometimes | |
7c913512 FM |
284 | |
285 | ||
23324ae1 | 286 | wxDF_TEXT |
7c913512 FM |
287 | |
288 | ||
23324ae1 | 289 | Text format (wxString) |
7c913512 FM |
290 | |
291 | ||
23324ae1 | 292 | wxDF_BITMAP |
7c913512 FM |
293 | |
294 | ||
23324ae1 | 295 | A bitmap (wxBitmap) |
7c913512 FM |
296 | |
297 | ||
23324ae1 | 298 | wxDF_METAFILE |
7c913512 FM |
299 | |
300 | ||
23324ae1 | 301 | A metafile (wxMetafile, Windows only) |
7c913512 FM |
302 | |
303 | ||
23324ae1 | 304 | wxDF_FILENAME |
7c913512 FM |
305 | |
306 | ||
23324ae1 | 307 | A list of filenames |
7c913512 FM |
308 | |
309 | ||
23324ae1 | 310 | wxDF_HTML |
7c913512 FM |
311 | |
312 | ||
23324ae1 FM |
313 | An HTML string. This is only valid when passed to wxSetClipboardData |
314 | when compiled with Visual C++ in non-Unicode mode | |
7c913512 FM |
315 | |
316 | ||
317 | ||
23324ae1 FM |
318 | As mentioned above, these standard formats may be passed to any function taking |
319 | wxDataFormat argument because wxDataFormat has an implicit conversion from | |
320 | them (or, to be precise from the type @c wxDataFormat::NativeFormat which is | |
321 | the type used by the underlying platform for data formats). | |
7c913512 | 322 | |
23324ae1 FM |
323 | Aside the standard formats, the application may also use custom formats which |
324 | are identified by their names (strings) and not numeric identifiers. Although | |
325 | internally custom format must be created (or @e registered) first, you | |
326 | shouldn't care about it because it is done automatically the first time the | |
327 | wxDataFormat object corresponding to a given format name is created. The only | |
328 | implication of this is that you should avoid having global wxDataFormat objects | |
329 | with non-default constructor because their constructors are executed before the | |
330 | program has time to perform all necessary initialisations and so an attempt to | |
331 | do clipboard format registration at this time will usually lead to a crash! | |
7c913512 | 332 | |
23324ae1 FM |
333 | @library{wxbase} |
334 | @category{dnd} | |
7c913512 | 335 | |
23324ae1 FM |
336 | @seealso |
337 | @ref overview_wxdndoverview "Clipboard and drag and drop overview", @ref | |
338 | overview_samplednd "DnD sample", wxDataObject | |
339 | */ | |
7c913512 | 340 | class wxDataFormat |
23324ae1 FM |
341 | { |
342 | public: | |
343 | /** | |
7c913512 | 344 | Constructs a data format object for a custom format identified by its name |
23324ae1 FM |
345 | @e format. |
346 | */ | |
347 | wxDataFormat(const wxChar format); | |
348 | ||
349 | /** | |
350 | Returns the name of a custom format (this function will fail for a standard | |
351 | format). | |
352 | */ | |
353 | wxString GetId(); | |
354 | ||
355 | /** | |
356 | Returns the platform-specific number identifying the format. | |
357 | */ | |
358 | NativeFormat GetType(); | |
359 | ||
360 | /** | |
361 | Sets the format to be the custom format identified by the given name. | |
362 | */ | |
363 | void SetId(const wxChar format); | |
364 | ||
365 | /** | |
366 | Sets the format to the given value, which should be one of wxDF_XXX constants. | |
367 | */ | |
368 | void SetType(NativeFormat format); | |
369 | ||
370 | /** | |
371 | Returns @true if the formats are different. | |
372 | */ | |
373 | bool operator !=(const wxDataFormat& format); | |
374 | ||
375 | /** | |
376 | Returns @true if the formats are equal. | |
377 | */ | |
378 | bool operator ==(const wxDataFormat& format); | |
379 | }; | |
380 | ||
381 | ||
382 | /** | |
383 | @class wxURLDataObject | |
384 | @wxheader{dataobj.h} | |
7c913512 | 385 | |
23324ae1 FM |
386 | wxURLDataObject is a wxDataObject containing an URL |
387 | and can be used e.g. when you need to put an URL on or retrieve it from the | |
388 | clipboard: | |
7c913512 | 389 | |
23324ae1 FM |
390 | @code |
391 | wxTheClipboard-SetData(new wxURLDataObject(url)); | |
392 | @endcode | |
7c913512 | 393 | |
23324ae1 FM |
394 | @library{wxcore} |
395 | @category{dnd} | |
7c913512 | 396 | |
23324ae1 FM |
397 | @seealso |
398 | @ref overview_wxdndoverview "Clipboard and drag and drop overview", wxDataObject | |
399 | */ | |
7c913512 | 400 | class wxURLDataObject |
23324ae1 FM |
401 | { |
402 | public: | |
403 | /** | |
7c913512 | 404 | Constructor, may be used to initialize the URL. If @e url is empty, |
23324ae1 FM |
405 | SetURL() can be used later. |
406 | */ | |
407 | wxURLDataObject(const wxString& url = wxEmptyString); | |
408 | ||
409 | /** | |
410 | Returns the URL stored by this object, as a string. | |
411 | */ | |
412 | #define wxString GetURL() /* implementation is private */ | |
413 | ||
414 | /** | |
415 | Sets the URL stored by this object. | |
416 | */ | |
417 | #define void SetURL(const wxString& url) /* implementation is private */ | |
418 | }; | |
419 | ||
420 | ||
421 | /** | |
422 | @class wxDataObject | |
423 | @wxheader{dataobj.h} | |
7c913512 | 424 | |
23324ae1 FM |
425 | A wxDataObject represents data that can be copied to or from the clipboard, or |
426 | dragged and dropped. The important thing about wxDataObject is that this is a | |
427 | 'smart' piece of data unlike 'dumb' data containers such as memory | |
428 | buffers or files. Being 'smart' here means that the data object itself should | |
429 | know what data formats it supports and how to render itself in each of | |
430 | its supported formats. | |
7c913512 | 431 | |
23324ae1 FM |
432 | A supported format, incidentally, is exactly the format in which the data can |
433 | be requested from a data object or from which the data object may be set. In | |
434 | the general case, an object may support different formats on 'input' and | |
435 | 'output', i.e. it may be able to render itself in a given format but not be | |
436 | created from data on this format or vice versa. wxDataObject defines an | |
437 | enumeration type | |
7c913512 | 438 | |
23324ae1 FM |
439 | @code |
440 | enum Direction | |
441 | { | |
442 | Get = 0x01, // format is supported by GetDataHere() | |
443 | Set = 0x02 // format is supported by SetData() | |
444 | }; | |
445 | @endcode | |
7c913512 FM |
446 | |
447 | which distinguishes between them. See | |
23324ae1 | 448 | wxDataFormat documentation for more about formats. |
7c913512 | 449 | |
23324ae1 FM |
450 | Not surprisingly, being 'smart' comes at a price of added complexity. This is |
451 | reasonable for the situations when you really need to support multiple formats, | |
452 | but may be annoying if you only want to do something simple like cut and paste | |
453 | text. | |
7c913512 | 454 | |
23324ae1 | 455 | To provide a solution for both cases, wxWidgets has two predefined classes |
7c913512 FM |
456 | which derive from wxDataObject: wxDataObjectSimple and |
457 | wxDataObjectComposite. | |
23324ae1 FM |
458 | wxDataObjectSimple is |
459 | the simplest wxDataObject possible and only holds data in a single format (such | |
460 | as HTML or text) and wxDataObjectComposite is | |
461 | the simplest way to implement a wxDataObject that does support multiple formats | |
462 | because it achieves this by simply holding several wxDataObjectSimple objects. | |
7c913512 | 463 | |
23324ae1 FM |
464 | So, you have several solutions when you need a wxDataObject class (and you need |
465 | one as soon as you want to transfer data via the clipboard or drag and drop): | |
7c913512 FM |
466 | |
467 | ||
468 | ||
23324ae1 | 469 | @b 1. Use one of the built-in classes |
7c913512 FM |
470 | |
471 | ||
23324ae1 FM |
472 | You may use wxTextDataObject, |
473 | wxBitmapDataObject or wxFileDataObject in the simplest cases when you only need | |
474 | to support one format and your data is either text, bitmap or list of files. | |
7c913512 FM |
475 | |
476 | ||
23324ae1 | 477 | @b 2. Use wxDataObjectSimple |
7c913512 FM |
478 | |
479 | ||
23324ae1 FM |
480 | Deriving from wxDataObjectSimple is the simplest |
481 | solution for custom data - you will only support one format and so probably | |
482 | won't be able to communicate with other programs, but data transfer will work | |
483 | in your program (or between different copies of it). | |
7c913512 FM |
484 | |
485 | ||
23324ae1 | 486 | @b 3. Use wxDataObjectComposite |
7c913512 FM |
487 | |
488 | ||
23324ae1 FM |
489 | This is a simple but powerful |
490 | solution which allows you to support any number of formats (either | |
491 | standard or custom if you combine it with the previous solution). | |
7c913512 FM |
492 | |
493 | ||
23324ae1 | 494 | @b 4. Use wxDataObject directly |
7c913512 FM |
495 | |
496 | ||
23324ae1 FM |
497 | This is the solution for |
498 | maximal flexibility and efficiency, but it is also the most difficult to | |
499 | implement. | |
7c913512 FM |
500 | |
501 | ||
502 | ||
23324ae1 FM |
503 | Please note that the easiest way to use drag and drop and the clipboard with |
504 | multiple formats is by using wxDataObjectComposite, but it is not the most | |
505 | efficient one as each wxDataObjectSimple would contain the whole data in its | |
506 | respective formats. Now imagine that you want to paste 200 pages of text in | |
507 | your proprietary format, as well as Word, RTF, HTML, Unicode and plain text to | |
508 | the clipboard and even today's computers are in trouble. For this case, you | |
509 | will have to derive from wxDataObject directly and make it enumerate its | |
510 | formats and provide the data in the requested format on demand. | |
7c913512 | 511 | |
23324ae1 FM |
512 | Note that neither the GTK+ data transfer mechanisms for clipboard and |
513 | drag and drop, nor OLE data transfer, copy any data until another application | |
514 | actually requests the data. This is in contrast to the 'feel' offered to the | |
515 | user of a program who would normally think that the data resides in the | |
516 | clipboard after having pressed 'Copy' - in reality it is only declared to be | |
517 | available. | |
7c913512 | 518 | |
23324ae1 | 519 | There are several predefined data object classes derived from |
7c913512 | 520 | wxDataObjectSimple: wxFileDataObject, |
23324ae1 FM |
521 | wxTextDataObject, |
522 | wxBitmapDataObject and | |
523 | wxURLDataObject | |
524 | which can be used without change. | |
7c913512 FM |
525 | |
526 | You may also derive your own data object classes from | |
23324ae1 FM |
527 | wxCustomDataObject for user-defined types. The |
528 | format of user-defined data is given as a mime-type string literal, such as | |
529 | "application/word" or "image/png". These strings are used as they are under | |
530 | Unix (so far only GTK+) to identify a format and are translated into their | |
531 | Windows equivalent under Win32 (using the OLE IDataObject for data exchange to | |
532 | and from the clipboard and for drag and drop). Note that the format string | |
533 | translation under Windows is not yet finished. | |
7c913512 | 534 | |
23324ae1 | 535 | @b wxPython note: At this time this class is not directly usable from wxPython. |
7c913512 | 536 | Derive a class from wxPyDataObjectSimple |
23324ae1 | 537 | instead. |
7c913512 | 538 | |
23324ae1 FM |
539 | @b wxPerl note: This class is not currently usable from wxPerl; you may |
540 | use Wx::PlDataObjectSimple instead. | |
7c913512 | 541 | |
23324ae1 FM |
542 | @library{wxcore} |
543 | @category{dnd} | |
7c913512 | 544 | |
23324ae1 FM |
545 | @seealso |
546 | @ref overview_wxdndoverview "Clipboard and drag and drop overview", @ref | |
547 | overview_samplednd "DnD sample", wxFileDataObject, wxTextDataObject, wxBitmapDataObject, wxCustomDataObject, wxDropTarget, wxDropSource, wxTextDropTarget, wxFileDropTarget | |
548 | */ | |
7c913512 | 549 | class wxDataObject |
23324ae1 FM |
550 | { |
551 | public: | |
552 | /** | |
553 | Constructor. | |
554 | */ | |
555 | wxDataObject(); | |
556 | ||
557 | /** | |
558 | Destructor. | |
559 | */ | |
560 | ~wxDataObject(); | |
561 | ||
562 | /** | |
7c913512 | 563 | Copy all supported formats in the given direction to the array pointed to by |
23324ae1 FM |
564 | @e formats. There is enough space for GetFormatCount(dir) formats in it. |
565 | */ | |
566 | virtual void GetAllFormats(wxDataFormat * formats, | |
567 | Direction dir = Get); | |
568 | ||
569 | /** | |
570 | The method will write the data of the format @e format in the buffer @e buf and | |
571 | return @true on success, @false on failure. | |
572 | */ | |
573 | virtual bool GetDataHere(const wxDataFormat& format, void buf); | |
574 | ||
575 | /** | |
576 | Returns the data size of the given format @e format. | |
577 | */ | |
578 | virtual size_t GetDataSize(const wxDataFormat& format); | |
579 | ||
580 | /** | |
581 | Returns the number of available formats for rendering or setting the data. | |
582 | */ | |
583 | virtual size_t GetFormatCount(Direction dir = Get); | |
584 | ||
585 | /** | |
586 | Returns the preferred format for either rendering the data (if @e dir is @c Get, | |
587 | its default value) or for setting it. Usually this will be the | |
588 | native format of the wxDataObject. | |
589 | */ | |
590 | virtual wxDataFormat GetPreferredFormat(Direction dir = Get); | |
591 | ||
592 | /** | |
593 | Set the data in the format @e format of the length @e len provided in the | |
594 | buffer @e buf. | |
595 | ||
596 | Returns @true on success, @false on failure. | |
597 | */ | |
598 | virtual bool SetData(const wxDataFormat& format, size_t len, | |
599 | const void buf); | |
600 | }; | |
601 | ||
602 | ||
603 | /** | |
604 | @class wxTextDataObject | |
605 | @wxheader{dataobj.h} | |
7c913512 | 606 | |
23324ae1 | 607 | wxTextDataObject is a specialization of wxDataObject for text data. It can be |
7c913512 | 608 | used without change to paste data into the wxClipboard |
23324ae1 FM |
609 | or a wxDropSource. A user may wish to derive a new |
610 | class from this class for providing text on-demand in order to minimize memory | |
611 | consumption when offering data in several formats, such as plain text and RTF | |
612 | because by default the text is stored in a string in this class, but it might | |
7c913512 FM |
613 | as well be generated when requested. For this, |
614 | wxTextDataObject::GetTextLength and | |
23324ae1 | 615 | wxTextDataObject::GetText will have to be overridden. |
7c913512 | 616 | |
23324ae1 FM |
617 | Note that if you already have the text inside a string, you will not achieve |
618 | any efficiency gain by overriding these functions because copying wxStrings is | |
619 | already a very efficient operation (data is not actually copied because | |
620 | wxStrings are reference counted). | |
7c913512 | 621 | |
23324ae1 FM |
622 | @b wxPython note: If you wish to create a derived wxTextDataObject class in |
623 | wxPython you should derive the class from wxPyTextDataObject | |
624 | in order to get Python-aware capabilities for the various virtual | |
625 | methods. | |
7c913512 | 626 | |
23324ae1 FM |
627 | @library{wxcore} |
628 | @category{dnd} | |
7c913512 | 629 | |
23324ae1 FM |
630 | @seealso |
631 | @ref overview_wxdndoverview "Clipboard and drag and drop overview", | |
632 | wxDataObject, wxDataObjectSimple, wxFileDataObject, wxBitmapDataObject | |
633 | */ | |
634 | class wxTextDataObject : public wxDataObjectSimple | |
635 | { | |
636 | public: | |
637 | /** | |
7c913512 | 638 | Constructor, may be used to initialise the text (otherwise |
23324ae1 FM |
639 | SetText() should be used later). |
640 | */ | |
641 | wxTextDataObject(const wxString& text = wxEmptyString); | |
642 | ||
643 | /** | |
644 | Returns the text associated with the data object. You may wish to override | |
645 | this method when offering data on-demand, but this is not required by | |
646 | wxWidgets' internals. Use this method to get data in text form from | |
647 | the wxClipboard. | |
648 | */ | |
649 | virtual wxString GetText(); | |
650 | ||
651 | /** | |
652 | Returns the data size. By default, returns the size of the text data | |
653 | set in the constructor or using SetText(). | |
654 | This can be overridden to provide text size data on-demand. It is recommended | |
655 | to return the text length plus 1 for a trailing zero, but this is not | |
656 | strictly required. | |
657 | */ | |
658 | virtual size_t GetTextLength(); | |
659 | ||
660 | /** | |
661 | Sets the text associated with the data object. This method is called | |
662 | when the data object receives the data and, by default, copies the text into | |
663 | the member variable. If you want to process the text on the fly you may wish to | |
664 | override this function. | |
665 | */ | |
666 | virtual void SetText(const wxString& strText); | |
667 | }; | |
668 | ||
669 | ||
670 | /** | |
671 | @class wxFileDataObject | |
672 | @wxheader{dataobj.h} | |
7c913512 FM |
673 | |
674 | wxFileDataObject is a specialization of wxDataObject | |
23324ae1 FM |
675 | for file names. The program works with it just as if it were a list of absolute |
676 | file | |
677 | names, but internally it uses the same format as | |
678 | Explorer and other compatible programs under Windows or GNOME/KDE filemanager | |
679 | under Unix which makes it possible to receive files from them using this | |
680 | class. | |
7c913512 | 681 | |
23324ae1 FM |
682 | @b Warning: Under all non-Windows platforms this class is currently |
683 | "input-only", i.e. you can receive the files from another application, but | |
684 | copying (or dragging) file(s) from a wxWidgets application is not currently | |
685 | supported. PS: GTK2 should work as well. | |
7c913512 | 686 | |
23324ae1 FM |
687 | @library{wxcore} |
688 | @category{dnd} | |
7c913512 | 689 | |
23324ae1 FM |
690 | @seealso |
691 | wxDataObject, wxDataObjectSimple, wxTextDataObject, wxBitmapDataObject, | |
692 | wxDataObject | |
693 | */ | |
694 | class wxFileDataObject : public wxDataObjectSimple | |
695 | { | |
696 | public: | |
697 | /** | |
698 | Constructor. | |
699 | */ | |
700 | wxFileDataObject(); | |
701 | ||
702 | /** | |
703 | @b MSW only: adds a file to the file list represented by this data object. | |
704 | */ | |
705 | virtual void AddFile(const wxString& file); | |
706 | ||
707 | /** | |
708 | Returns the array of file names. | |
709 | */ | |
710 | const wxArrayString GetFilenames(); | |
711 | }; |