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