dataobj.h 28 KB

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