]>
Commit | Line | Data |
---|---|---|
3f480da3 | 1 | /////////////////////////////////////////////////////////////////////////////// |
e1ee679c | 2 | // Name: wx/dataobj.h |
3f480da3 | 3 | // Purpose: common data object classes |
e1ee679c | 4 | // Author: Vadim Zeitlin, Robert Roebling |
3f480da3 VZ |
5 | // Modified by: |
6 | // Created: 26.05.99 | |
77ffb593 | 7 | // Copyright: (c) wxWidgets Team |
65571936 | 8 | // Licence: wxWindows licence |
3f480da3 VZ |
9 | /////////////////////////////////////////////////////////////////////////////// |
10 | ||
8b53e5a2 RR |
11 | #ifndef _WX_DATAOBJ_H_BASE_ |
12 | #define _WX_DATAOBJ_H_BASE_ | |
13 | ||
e1ee679c VZ |
14 | // ---------------------------------------------------------------------------- |
15 | // headers | |
16 | // ---------------------------------------------------------------------------- | |
e1ee679c | 17 | #include "wx/defs.h" |
49de4949 DE |
18 | |
19 | #if wxUSE_DATAOBJ | |
20 | ||
e1ee679c VZ |
21 | #include "wx/string.h" |
22 | #include "wx/bitmap.h" | |
23 | #include "wx/list.h" | |
a6abcf2e | 24 | #include "wx/arrstr.h" |
e1ee679c VZ |
25 | |
26 | // ============================================================================ | |
27 | /* | |
28 | Generic data transfer related classes. The class hierarchy is as follows: | |
29 | ||
30 | - wxDataObject- | |
31 | / \ | |
32 | / \ | |
33 | wxDataObjectSimple wxDataObjectComposite | |
34 | / | \ | |
35 | / | \ | |
36 | wxTextDataObject | wxBitmapDataObject | |
37 | | | |
38 | wxCustomDataObject | |
39 | ||
40 | */ | |
41 | // ============================================================================ | |
42 | ||
43 | // ---------------------------------------------------------------------------- | |
44 | // wxDataFormat class is declared in platform-specific headers: it represents | |
45 | // a format for data which may be either one of the standard ones (text, | |
46 | // bitmap, ...) or a custom one which is then identified by a unique string. | |
47 | // ---------------------------------------------------------------------------- | |
48 | ||
49 | /* the class interface looks like this (pseudo code): | |
50 | ||
51 | class wxDataFormat | |
52 | { | |
53 | public: | |
54 | typedef <integral type> NativeFormat; | |
55 | ||
56 | wxDataFormat(NativeFormat format = wxDF_INVALID); | |
a1eb65c2 | 57 | wxDataFormat(const wxString& format); |
e1ee679c VZ |
58 | |
59 | wxDataFormat& operator=(NativeFormat format); | |
60 | wxDataFormat& operator=(const wxDataFormat& format); | |
61 | ||
62 | bool operator==(NativeFormat format) const; | |
63 | bool operator!=(NativeFormat format) const; | |
64 | ||
65 | void SetType(NativeFormat format); | |
66 | NativeFormat GetType() const; | |
67 | ||
68 | wxString GetId() const; | |
a1eb65c2 | 69 | void SetId(const wxString& format); |
e1ee679c VZ |
70 | }; |
71 | ||
72 | */ | |
73 | ||
74 | #if defined(__WXMSW__) | |
75 | #include "wx/msw/ole/dataform.h" | |
76 | #elif defined(__WXMOTIF__) | |
77 | #include "wx/motif/dataform.h" | |
1be7a35c | 78 | #elif defined(__WXGTK20__) |
e1ee679c | 79 | #include "wx/gtk/dataform.h" |
1be7a35c MR |
80 | #elif defined(__WXGTK__) |
81 | #include "wx/gtk1/dataform.h" | |
83df96d6 JS |
82 | #elif defined(__WXX11__) |
83 | #include "wx/x11/dataform.h" | |
e7549107 | 84 | #elif defined(__WXMAC__) |
ef0e9220 | 85 | #include "wx/osx/dataform.h" |
aa3d0277 DE |
86 | #elif defined(__WXCOCOA__) |
87 | #include "wx/cocoa/dataform.h" | |
4004aba3 DW |
88 | #elif defined(__WXPM__) |
89 | #include "wx/os2/dataform.h" | |
e1ee679c VZ |
90 | #endif |
91 | ||
0c2b453f VZ |
92 | // the value for default argument to some functions (corresponds to |
93 | // wxDF_INVALID) | |
53a2db12 | 94 | extern WXDLLIMPEXP_CORE const wxDataFormat& wxFormatInvalid; |
0c2b453f | 95 | |
e1ee679c VZ |
96 | // ---------------------------------------------------------------------------- |
97 | // wxDataObject represents a piece of data which knows which formats it | |
98 | // supports and knows how to render itself in each of them - GetDataHere(), | |
99 | // and how to restore data from the buffer (SetData()). | |
100 | // | |
101 | // Although this class may be used directly (i.e. custom classes may be | |
102 | // derived from it), in many cases it might be simpler to use either | |
103 | // wxDataObjectSimple or wxDataObjectComposite classes. | |
104 | // | |
105 | // A data object may be "read only", i.e. support only GetData() functions or | |
106 | // "read-write", i.e. support both GetData() and SetData() (in principle, it | |
107 | // might be "write only" too, but this is rare). Moreover, it doesn't have to | |
108 | // support the same formats in Get() and Set() directions: for example, a data | |
109 | // object containing JPEG image might accept BMPs in GetData() because JPEG | |
110 | // image may be easily transformed into BMP but not in SetData(). Accordingly, | |
111 | // all methods dealing with formats take an additional "direction" argument | |
112 | // which is either SET or GET and which tells the function if the format needs | |
113 | // to be supported by SetData() or GetDataHere(). | |
114 | // ---------------------------------------------------------------------------- | |
115 | ||
53a2db12 | 116 | class WXDLLIMPEXP_CORE wxDataObjectBase |
e1ee679c VZ |
117 | { |
118 | public: | |
119 | enum Direction | |
120 | { | |
121 | Get = 0x01, // format is supported by GetDataHere() | |
122 | Set = 0x02, // format is supported by SetData() | |
123 | Both = 0x03 // format is supported by both (unused currently) | |
124 | }; | |
125 | ||
126 | // this class is polymorphic, hence it needs a virtual dtor | |
127 | virtual ~wxDataObjectBase(); | |
128 | ||
129 | // get the best suited format for rendering our data | |
130 | virtual wxDataFormat GetPreferredFormat(Direction dir = Get) const = 0; | |
131 | ||
132 | // get the number of formats we support | |
133 | virtual size_t GetFormatCount(Direction dir = Get) const = 0; | |
134 | ||
135 | // return all formats in the provided array (of size GetFormatCount()) | |
136 | virtual void GetAllFormats(wxDataFormat *formats, | |
137 | Direction dir = Get) const = 0; | |
138 | ||
139 | // get the (total) size of data for the given format | |
140 | virtual size_t GetDataSize(const wxDataFormat& format) const = 0; | |
141 | ||
142 | // copy raw data (in the specified format) to the provided buffer, return | |
68379eaf | 143 | // true if data copied successfully, false otherwise |
e1ee679c VZ |
144 | virtual bool GetDataHere(const wxDataFormat& format, void *buf) const = 0; |
145 | ||
146 | // get data from the buffer of specified length (in the given format), | |
68379eaf | 147 | // return true if the data was read successfully, false otherwise |
f2491e2d VZ |
148 | virtual bool SetData(const wxDataFormat& WXUNUSED(format), |
149 | size_t WXUNUSED(len), const void * WXUNUSED(buf)) | |
9e2896e5 | 150 | { |
68379eaf | 151 | return false; |
9e2896e5 | 152 | } |
d9317fd4 | 153 | |
68379eaf | 154 | // returns true if this format is supported |
d9317fd4 | 155 | bool IsSupported(const wxDataFormat& format, Direction dir = Get) const; |
e1ee679c VZ |
156 | }; |
157 | ||
158 | // ---------------------------------------------------------------------------- | |
159 | // include the platform-specific declarations of wxDataObject | |
160 | // ---------------------------------------------------------------------------- | |
161 | ||
8b53e5a2 | 162 | #if defined(__WXMSW__) |
3f480da3 | 163 | #include "wx/msw/ole/dataobj.h" |
8b53e5a2 | 164 | #elif defined(__WXMOTIF__) |
3f480da3 | 165 | #include "wx/motif/dataobj.h" |
7266b672 JS |
166 | #elif defined(__WXX11__) |
167 | #include "wx/x11/dataobj.h" | |
d74c6a95 | 168 | #elif defined(__WXGTK20__) |
3f480da3 | 169 | #include "wx/gtk/dataobj.h" |
d74c6a95 MW |
170 | #elif defined(__WXGTK__) |
171 | #include "wx/gtk1/dataobj.h" | |
8b53e5a2 | 172 | #elif defined(__WXMAC__) |
ef0e9220 | 173 | #include "wx/osx/dataobj.h" |
aa3d0277 DE |
174 | #elif defined(__WXCOCOA__) |
175 | #include "wx/cocoa/dataobj.h" | |
1777b9bb | 176 | #elif defined(__WXPM__) |
6dddc146 | 177 | #include "wx/os2/dataobj.h" |
8b53e5a2 RR |
178 | #endif |
179 | ||
e1ee679c VZ |
180 | // ---------------------------------------------------------------------------- |
181 | // wxDataObjectSimple is a wxDataObject which only supports one format (in | |
68379eaf | 182 | // both Get and Set directions, but you may return false from GetDataHere() or |
e1ee679c VZ |
183 | // SetData() if one of them is not supported). This is the simplest possible |
184 | // wxDataObject implementation. | |
185 | // | |
186 | // This is still an "abstract base class" (although it doesn't have any pure | |
187 | // virtual functions), to use it you should derive from it and implement | |
188 | // GetDataSize(), GetDataHere() and SetData() functions because the base class | |
189 | // versions don't do anything - they just return "not implemented". | |
190 | // | |
191 | // This class should be used when you provide data in only one format (no | |
192 | // conversion to/from other formats), either a standard or a custom one. | |
193 | // Otherwise, you should use wxDataObjectComposite or wxDataObject directly. | |
194 | // ---------------------------------------------------------------------------- | |
3f480da3 | 195 | |
53a2db12 | 196 | class WXDLLIMPEXP_CORE wxDataObjectSimple : public wxDataObject |
3f480da3 | 197 | { |
e1ee679c VZ |
198 | public: |
199 | // ctor takes the format we support, but it can also be set later with | |
200 | // SetFormat() | |
1e8335b0 | 201 | wxDataObjectSimple(const wxDataFormat& format = wxFormatInvalid) |
e1ee679c VZ |
202 | : m_format(format) |
203 | { | |
204 | } | |
205 | ||
206 | // get/set the format we support | |
207 | const wxDataFormat& GetFormat() const { return m_format; } | |
208 | void SetFormat(const wxDataFormat& format) { m_format = format; } | |
209 | ||
210 | // virtual functions to override in derived class (the base class versions | |
211 | // just return "not implemented") | |
212 | // ----------------------------------------------------------------------- | |
213 | ||
214 | // get the size of our data | |
215 | virtual size_t GetDataSize() const | |
216 | { return 0; } | |
3f480da3 | 217 | |
e1ee679c VZ |
218 | // copy our data to the buffer |
219 | virtual bool GetDataHere(void *WXUNUSED(buf)) const | |
68379eaf | 220 | { return false; } |
e1ee679c VZ |
221 | |
222 | // copy data from buffer to our data | |
e30d5976 | 223 | virtual bool SetData(size_t WXUNUSED(len), const void *WXUNUSED(buf)) |
68379eaf | 224 | { return false; } |
e1ee679c VZ |
225 | |
226 | // implement base class pure virtuals | |
227 | // ---------------------------------- | |
4004aba3 | 228 | virtual wxDataFormat GetPreferredFormat(wxDataObjectBase::Direction WXUNUSED(dir) = Get) const |
e1ee679c | 229 | { return m_format; } |
4004aba3 | 230 | virtual size_t GetFormatCount(wxDataObjectBase::Direction WXUNUSED(dir) = Get) const |
e1ee679c VZ |
231 | { return 1; } |
232 | virtual void GetAllFormats(wxDataFormat *formats, | |
4004aba3 | 233 | wxDataObjectBase::Direction WXUNUSED(dir) = Get) const |
e1ee679c VZ |
234 | { *formats = m_format; } |
235 | virtual size_t GetDataSize(const wxDataFormat& WXUNUSED(format)) const | |
236 | { return GetDataSize(); } | |
237 | virtual bool GetDataHere(const wxDataFormat& WXUNUSED(format), | |
238 | void *buf) const | |
239 | { return GetDataHere(buf); } | |
240 | virtual bool SetData(const wxDataFormat& WXUNUSED(format), | |
241 | size_t len, const void *buf) | |
242 | { return SetData(len, buf); } | |
243 | ||
244 | private: | |
245 | // the one and only format we support | |
246 | wxDataFormat m_format; | |
fc7a2a60 | 247 | |
c0c133e1 | 248 | wxDECLARE_NO_COPY_CLASS(wxDataObjectSimple); |
e1ee679c VZ |
249 | }; |
250 | ||
251 | // ---------------------------------------------------------------------------- | |
252 | // wxDataObjectComposite is the simplest way to implement wxDataObject | |
253 | // supporting multiple formats. It contains several wxDataObjectSimple and | |
254 | // supports all formats supported by any of them. | |
255 | // | |
256 | // This class shouldn't be (normally) derived from, but may be used directly. | |
257 | // If you need more flexibility than what it provides, you should probably use | |
258 | // wxDataObject directly. | |
259 | // ---------------------------------------------------------------------------- | |
260 | ||
f6bcfd97 | 261 | WX_DECLARE_EXPORTED_LIST(wxDataObjectSimple, wxSimpleDataObjectList); |
e1ee679c | 262 | |
53a2db12 | 263 | class WXDLLIMPEXP_CORE wxDataObjectComposite : public wxDataObject |
e1ee679c | 264 | { |
3f480da3 | 265 | public: |
e1ee679c | 266 | // ctor |
e6b01b78 | 267 | wxDataObjectComposite(); |
222ed1d6 | 268 | virtual ~wxDataObjectComposite(); |
e1ee679c VZ |
269 | |
270 | // add data object (it will be deleted by wxDataObjectComposite, hence it | |
271 | // must be allocated on the heap) whose format will become the preferred | |
68379eaf WS |
272 | // one if preferred == true |
273 | void Add(wxDataObjectSimple *dataObject, bool preferred = false); | |
3f480da3 | 274 | |
c072c757 | 275 | // Report the format passed to the SetData method. This should be the |
1d4b9c37 | 276 | // format of the data object within the composite that received data from |
c072c757 | 277 | // the clipboard or the DnD operation. You can use this method to find |
1d4b9c37 | 278 | // out what kind of data object was received. |
c072c757 RD |
279 | wxDataFormat GetReceivedFormat() const; |
280 | ||
1d4b9c37 VZ |
281 | // Returns the pointer to the object which supports this format or NULL. |
282 | // The returned pointer is owned by wxDataObjectComposite and must | |
283 | // therefore not be destroyed by the caller. | |
284 | wxDataObjectSimple *GetObject(const wxDataFormat& format, | |
285 | wxDataObjectBase::Direction dir = Get) const; | |
286 | ||
e1ee679c VZ |
287 | // implement base class pure virtuals |
288 | // ---------------------------------- | |
4004aba3 DW |
289 | virtual wxDataFormat GetPreferredFormat(wxDataObjectBase::Direction dir = Get) const; |
290 | virtual size_t GetFormatCount(wxDataObjectBase::Direction dir = Get) const; | |
291 | virtual void GetAllFormats(wxDataFormat *formats, wxDataObjectBase::Direction dir = Get) const; | |
e1ee679c VZ |
292 | virtual size_t GetDataSize(const wxDataFormat& format) const; |
293 | virtual bool GetDataHere(const wxDataFormat& format, void *buf) const; | |
294 | virtual bool SetData(const wxDataFormat& format, size_t len, const void *buf); | |
e1b435af MB |
295 | #if defined(__WXMSW__) |
296 | virtual const void* GetSizeFromBuffer( const void* buffer, size_t* size, | |
297 | const wxDataFormat& format ); | |
298 | virtual void* SetSizeInBuffer( void* buffer, size_t size, | |
299 | const wxDataFormat& format ); | |
300 | virtual size_t GetBufferOffset( const wxDataFormat& format ); | |
301 | #endif | |
3f480da3 | 302 | |
e1ee679c VZ |
303 | private: |
304 | // the list of all (simple) data objects whose formats we support | |
305 | wxSimpleDataObjectList m_dataObjects; | |
3f480da3 | 306 | |
e1ee679c VZ |
307 | // the index of the preferred one (0 initially, so by default the first |
308 | // one is the preferred) | |
309 | size_t m_preferred; | |
fc7a2a60 | 310 | |
c072c757 RD |
311 | wxDataFormat m_receivedFormat; |
312 | ||
c0c133e1 | 313 | wxDECLARE_NO_COPY_CLASS(wxDataObjectComposite); |
e1ee679c | 314 | }; |
3f480da3 | 315 | |
e1ee679c VZ |
316 | // ============================================================================ |
317 | // Standard implementations of wxDataObjectSimple which can be used directly | |
318 | // (i.e. without having to derive from them) for standard data type transfers. | |
319 | // | |
320 | // Note that although all of them can work with provided data, you can also | |
321 | // override their virtual GetXXX() functions to only provide data on demand. | |
322 | // ============================================================================ | |
3f480da3 | 323 | |
e1ee679c VZ |
324 | // ---------------------------------------------------------------------------- |
325 | // wxTextDataObject contains text data | |
326 | // ---------------------------------------------------------------------------- | |
3f480da3 | 327 | |
98ecad06 VZ |
328 | #if wxUSE_UNICODE |
329 | #if defined(__WXGTK20__) | |
330 | #define wxNEEDS_UTF8_FOR_TEXT_DATAOBJ | |
331 | #elif defined(__WXMAC__) | |
a25a1773 | 332 | #define wxNEEDS_UTF16_FOR_TEXT_DATAOBJ |
98ecad06 VZ |
333 | #endif |
334 | #endif // wxUSE_UNICODE | |
335 | ||
b8acf11e RD |
336 | class WXDLLIMPEXP_CORE wxHTMLDataObject : public wxDataObjectSimple |
337 | { | |
338 | public: | |
339 | // ctor: you can specify the text here or in SetText(), or override | |
340 | // GetText() | |
341 | wxHTMLDataObject(const wxString& html = wxEmptyString) | |
342 | : wxDataObjectSimple(wxDF_HTML), | |
343 | m_html(html) | |
344 | { | |
345 | } | |
346 | ||
347 | // virtual functions which you may override if you want to provide text on | |
348 | // demand only - otherwise, the trivial default versions will be used | |
349 | virtual size_t GetLength() const { return m_html.Len() + 1; } | |
350 | virtual wxString GetHTML() const { return m_html; } | |
351 | virtual void SetHTML(const wxString& html) { m_html = html; } | |
352 | ||
353 | virtual size_t GetDataSize() const; | |
354 | virtual bool GetDataHere(void *buf) const; | |
355 | virtual bool SetData(size_t len, const void *buf); | |
356 | ||
357 | // Must provide overloads to avoid hiding them (and warnings about it) | |
358 | virtual size_t GetDataSize(const wxDataFormat&) const | |
359 | { | |
360 | return GetDataSize(); | |
361 | } | |
362 | virtual bool GetDataHere(const wxDataFormat&, void *buf) const | |
363 | { | |
364 | return GetDataHere(buf); | |
365 | } | |
366 | virtual bool SetData(const wxDataFormat&, size_t len, const void *buf) | |
367 | { | |
368 | return SetData(len, buf); | |
369 | } | |
370 | ||
371 | private: | |
372 | wxString m_html; | |
373 | }; | |
374 | ||
53a2db12 | 375 | class WXDLLIMPEXP_CORE wxTextDataObject : public wxDataObjectSimple |
e1ee679c VZ |
376 | { |
377 | public: | |
378 | // ctor: you can specify the text here or in SetText(), or override | |
379 | // GetText() | |
380 | wxTextDataObject(const wxString& text = wxEmptyString) | |
17a1ebd1 VZ |
381 | : wxDataObjectSimple( |
382 | #if wxUSE_UNICODE | |
383 | wxDF_UNICODETEXT | |
384 | #else | |
385 | wxDF_TEXT | |
386 | #endif | |
387 | ), | |
e1b435af | 388 | m_text(text) |
e1ee679c VZ |
389 | { |
390 | } | |
3f480da3 | 391 | |
e1ee679c VZ |
392 | // virtual functions which you may override if you want to provide text on |
393 | // demand only - otherwise, the trivial default versions will be used | |
394 | virtual size_t GetTextLength() const { return m_text.Len() + 1; } | |
395 | virtual wxString GetText() const { return m_text; } | |
396 | virtual void SetText(const wxString& text) { m_text = text; } | |
397 | ||
398 | // implement base class pure virtuals | |
399 | // ---------------------------------- | |
c7d6d883 | 400 | |
17a1ebd1 | 401 | // some platforms have 2 and not 1 format for text data |
98ecad06 | 402 | #if defined(wxNEEDS_UTF8_FOR_TEXT_DATAOBJ) || defined(wxNEEDS_UTF16_FOR_TEXT_DATAOBJ) |
25758297 SC |
403 | virtual size_t GetFormatCount(Direction WXUNUSED(dir) = Get) const { return 2; } |
404 | virtual void GetAllFormats(wxDataFormat *formats, | |
405 | wxDataObjectBase::Direction WXUNUSED(dir) = Get) const; | |
406 | ||
407 | virtual size_t GetDataSize() const { return GetDataSize(GetPreferredFormat()); } | |
408 | virtual bool GetDataHere(void *buf) const { return GetDataHere(GetPreferredFormat(), buf); } | |
409 | virtual bool SetData(size_t len, const void *buf) { return SetData(GetPreferredFormat(), len, buf); } | |
410 | ||
c7d6d883 RR |
411 | size_t GetDataSize(const wxDataFormat& format) const; |
412 | bool GetDataHere(const wxDataFormat& format, void *pBuf) const; | |
413 | bool SetData(const wxDataFormat& format, size_t nLen, const void* pBuf); | |
98ecad06 | 414 | #else // !wxNEEDS_UTF{8,16}_FOR_TEXT_DATAOBJ |
e1ee679c VZ |
415 | virtual size_t GetDataSize() const; |
416 | virtual bool GetDataHere(void *buf) const; | |
417 | virtual bool SetData(size_t len, const void *buf); | |
6f02a879 VZ |
418 | // Must provide overloads to avoid hiding them (and warnings about it) |
419 | virtual size_t GetDataSize(const wxDataFormat&) const | |
420 | { | |
421 | return GetDataSize(); | |
422 | } | |
423 | virtual bool GetDataHere(const wxDataFormat&, void *buf) const | |
424 | { | |
425 | return GetDataHere(buf); | |
426 | } | |
427 | virtual bool SetData(const wxDataFormat&, size_t len, const void *buf) | |
428 | { | |
429 | return SetData(len, buf); | |
430 | } | |
98ecad06 | 431 | #endif // different wxTextDataObject implementations |
fc7a2a60 | 432 | |
c7d6d883 RR |
433 | private: |
434 | wxString m_text; | |
68379eaf | 435 | |
c0c133e1 | 436 | wxDECLARE_NO_COPY_CLASS(wxTextDataObject); |
e1ee679c | 437 | }; |
3f480da3 | 438 | |
e1ee679c VZ |
439 | // ---------------------------------------------------------------------------- |
440 | // wxBitmapDataObject contains a bitmap | |
441 | // ---------------------------------------------------------------------------- | |
3f480da3 | 442 | |
53a2db12 | 443 | class WXDLLIMPEXP_CORE wxBitmapDataObjectBase : public wxDataObjectSimple |
e1ee679c VZ |
444 | { |
445 | public: | |
446 | // ctor: you can specify the bitmap here or in SetBitmap(), or override | |
447 | // GetBitmap() | |
448 | wxBitmapDataObjectBase(const wxBitmap& bitmap = wxNullBitmap) | |
449 | : wxDataObjectSimple(wxDF_BITMAP), m_bitmap(bitmap) | |
450 | { | |
451 | } | |
452 | ||
453 | // virtual functions which you may override if you want to provide data on | |
454 | // demand only - otherwise, the trivial default versions will be used | |
455 | virtual wxBitmap GetBitmap() const { return m_bitmap; } | |
456 | virtual void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; } | |
457 | ||
b068c4e8 | 458 | protected: |
e1ee679c | 459 | wxBitmap m_bitmap; |
fc7a2a60 | 460 | |
c0c133e1 | 461 | wxDECLARE_NO_COPY_CLASS(wxBitmapDataObjectBase); |
e1ee679c VZ |
462 | }; |
463 | ||
464 | // ---------------------------------------------------------------------------- | |
465 | // wxFileDataObject contains a list of filenames | |
9e2896e5 VZ |
466 | // |
467 | // NB: notice that this is a "write only" object, it can only be filled with | |
468 | // data from drag and drop operation. | |
e1ee679c VZ |
469 | // ---------------------------------------------------------------------------- |
470 | ||
53a2db12 | 471 | class WXDLLIMPEXP_CORE wxFileDataObjectBase : public wxDataObjectSimple |
e1ee679c VZ |
472 | { |
473 | public: | |
9e2896e5 | 474 | // ctor: use AddFile() later to fill the array |
e1ee679c VZ |
475 | wxFileDataObjectBase() : wxDataObjectSimple(wxDF_FILENAME) { } |
476 | ||
9e2896e5 | 477 | // get a reference to our array |
b068c4e8 | 478 | const wxArrayString& GetFilenames() const { return m_filenames; } |
e1ee679c | 479 | |
9e2896e5 | 480 | protected: |
e1ee679c | 481 | wxArrayString m_filenames; |
6dddc146 | 482 | |
c0c133e1 | 483 | wxDECLARE_NO_COPY_CLASS(wxFileDataObjectBase); |
e1ee679c VZ |
484 | }; |
485 | ||
486 | // ---------------------------------------------------------------------------- | |
487 | // wxCustomDataObject contains arbitrary untyped user data. | |
488 | // | |
489 | // It is understood that this data can be copied bitwise. | |
490 | // ---------------------------------------------------------------------------- | |
491 | ||
53a2db12 | 492 | class WXDLLIMPEXP_CORE wxCustomDataObject : public wxDataObjectSimple |
e1ee679c VZ |
493 | { |
494 | public: | |
495 | // if you don't specify the format in the ctor, you can still use | |
496 | // SetFormat() later | |
0c2b453f | 497 | wxCustomDataObject(const wxDataFormat& format = wxFormatInvalid); |
e1ee679c VZ |
498 | |
499 | // the dtor calls Free() | |
500 | virtual ~wxCustomDataObject(); | |
501 | ||
502 | // you can call SetData() to set m_data: it will make a copy of the data | |
503 | // you pass - or you can use TakeData() which won't copy anything, but | |
504 | // will take ownership of data (i.e. will call Free() on it later) | |
505 | void TakeData(size_t size, void *data); | |
506 | ||
507 | // this function is called to allocate "size" bytes of memory from | |
508 | // SetData(). The default version uses operator new[]. | |
509 | virtual void *Alloc(size_t size); | |
510 | ||
511 | // this function is called when the data is freed, you may override it to | |
512 | // anything you want (or may be nothing at all). The default version calls | |
513 | // operator delete[] on m_data | |
514 | virtual void Free(); | |
515 | ||
516 | // get data: you may override these functions if you wish to provide data | |
517 | // only when it's requested | |
518 | virtual size_t GetSize() const { return m_size; } | |
519 | virtual void *GetData() const { return m_data; } | |
520 | ||
521 | // implement base class pure virtuals | |
522 | // ---------------------------------- | |
523 | virtual size_t GetDataSize() const; | |
524 | virtual bool GetDataHere(void *buf) const; | |
525 | virtual bool SetData(size_t size, const void *buf); | |
6f02a879 VZ |
526 | // Must provide overloads to avoid hiding them (and warnings about it) |
527 | virtual size_t GetDataSize(const wxDataFormat&) const | |
528 | { | |
529 | return GetDataSize(); | |
530 | } | |
531 | virtual bool GetDataHere(const wxDataFormat&, void *buf) const | |
532 | { | |
533 | return GetDataHere(buf); | |
534 | } | |
535 | virtual bool SetData(const wxDataFormat&, size_t len, const void *buf) | |
536 | { | |
537 | return SetData(len, buf); | |
538 | } | |
e1ee679c VZ |
539 | |
540 | private: | |
541 | size_t m_size; | |
542 | void *m_data; | |
6dddc146 | 543 | |
c0c133e1 | 544 | wxDECLARE_NO_COPY_CLASS(wxCustomDataObject); |
3f480da3 VZ |
545 | }; |
546 | ||
e1ee679c VZ |
547 | // ---------------------------------------------------------------------------- |
548 | // include platform-specific declarations of wxXXXBase classes | |
549 | // ---------------------------------------------------------------------------- | |
3f480da3 | 550 | |
e1ee679c VZ |
551 | #if defined(__WXMSW__) |
552 | #include "wx/msw/ole/dataobj2.h" | |
444ad3a7 | 553 | // wxURLDataObject defined in msw/ole/dataobj2.h |
d613be55 RR |
554 | #elif defined(__WXGTK20__) |
555 | #include "wx/gtk/dataobj2.h" | |
556 | // wxURLDataObject defined in msw/ole/dataobj2.h | |
557 | ||
03647350 | 558 | #else |
d613be55 | 559 | #if defined(__WXGTK__) |
d74c6a95 | 560 | #include "wx/gtk1/dataobj2.h" |
9691c806 RR |
561 | #elif defined(__WXX11__) |
562 | #include "wx/x11/dataobj2.h" | |
dd38c875 MB |
563 | #elif defined(__WXMOTIF__) |
564 | #include "wx/motif/dataobj2.h" | |
444ad3a7 | 565 | #elif defined(__WXMAC__) |
ef0e9220 | 566 | #include "wx/osx/dataobj2.h" |
aa3d0277 DE |
567 | #elif defined(__WXCOCOA__) |
568 | #include "wx/cocoa/dataobj2.h" | |
444ad3a7 VZ |
569 | #elif defined(__WXPM__) |
570 | #include "wx/os2/dataobj2.h" | |
571 | #endif | |
572 | ||
573 | // wxURLDataObject is simply wxTextDataObject with a different name | |
53a2db12 | 574 | class WXDLLIMPEXP_CORE wxURLDataObject : public wxTextDataObject |
444ad3a7 VZ |
575 | { |
576 | public: | |
0463eea9 VZ |
577 | wxURLDataObject(const wxString& url = wxEmptyString) |
578 | : wxTextDataObject(url) | |
579 | { | |
580 | } | |
581 | ||
444ad3a7 | 582 | wxString GetURL() const { return GetText(); } |
e6d318c2 | 583 | void SetURL(const wxString& url) { SetText(url); } |
444ad3a7 | 584 | }; |
d613be55 | 585 | #endif |
e1ee679c | 586 | |
49de4949 DE |
587 | #endif // wxUSE_DATAOBJ |
588 | ||
e1ee679c | 589 | #endif // _WX_DATAOBJ_H_BASE_ |