1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: declaration of the wxDataObject class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_OLEDATAOBJ_H
13 #define _WX_OLEDATAOBJ_H
15 // ----------------------------------------------------------------------------
16 // forward declarations
17 // ----------------------------------------------------------------------------
20 // ----------------------------------------------------------------------------
21 // wxDataObject is a "smart" and polymorphic piece of data.
23 // TODO it's currently "read-only" from COM point of view, i.e. we don't support
24 // SetData. We don't support all advise functions neither (but it's easy to
25 // do if we really want them)
26 // ----------------------------------------------------------------------------
28 class WXDLLEXPORT wxDataObject
31 // function to return symbolic name of clipboard format (debug messages)
32 static const char *GetFormatName(wxDataFormat format
);
36 virtual ~wxDataObject();
38 // pure virtuals to override
39 // get the best suited format for our data
40 virtual wxDataFormat
GetPreferredFormat() const = 0;
41 // decide if we support this format (should be one of values of
42 // wxDataFormatId enumerations or a user-defined format)
43 virtual bool IsSupportedFormat(wxDataFormat format
) const = 0;
44 // get the (total) size of data
45 virtual size_t GetDataSize() const = 0;
46 // copy raw data to provided pointer
47 virtual void GetDataHere(void *pBuf
) const = 0;
50 // retrieve IDataObject interface (for other OLE related classes)
51 IDataObject
*GetInterface() const { return m_pIDataObject
; }
53 ////// wxGTK compatibility: hopefully to become the preferred API.
54 virtual wxDataFormat
GetFormat() const { return GetPreferredFormat(); }
57 IDataObject
*m_pIDataObject
; // pointer to the COM interface
60 // ----------------------------------------------------------------------------
61 // wxTextDataObject is a specialization of wxDataObject for text data
62 // ----------------------------------------------------------------------------
63 class WXDLLEXPORT wxTextDataObject
: public wxDataObject
67 wxTextDataObject() { }
68 wxTextDataObject(const wxString
& strText
) : m_strText(strText
) { }
69 void Init(const wxString
& strText
) { m_strText
= strText
; }
71 // implement base class pure virtuals
72 virtual wxDataFormat
GetPreferredFormat() const
74 virtual bool IsSupportedFormat(wxDataFormat format
) const
75 { return format
== wxDF_TEXT
|| format
== wxDF_LOCALE
; }
76 virtual size_t GetDataSize() const
77 { return m_strText
.Len() + 1; } // +1 for trailing '\0'of course
78 virtual void GetDataHere(void *pBuf
) const
79 { memcpy(pBuf
, m_strText
.c_str(), GetDataSize()); }
81 ////// wxGTK compatibility: hopefully to become the preferred API.
82 void SetText(const wxString
& strText
) { m_strText
= strText
; }
83 wxString
GetText() const { return m_strText
; }
84 virtual wxDataFormat
GetFormat() const { return wxDF_TEXT
; }
90 // ----------------------------------------------------------------------------
91 // @@@ TODO: wx{Bitmap|Metafile|...}DataObject
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
95 // wxBitmapDataObject is a specialization of wxDataObject for bitmap data
96 // ----------------------------------------------------------------------------
98 // TODO: implement OLE side of things. At present, it's just for clipboard
100 class WXDLLEXPORT wxBitmapDataObject
: public wxDataObject
104 wxBitmapDataObject() {};
105 wxBitmapDataObject(const wxBitmap
& bitmap
): m_bitmap(bitmap
) {}
106 void SetBitmap(const wxBitmap
& bitmap
) { m_bitmap
= bitmap
; }
107 wxBitmap
GetBitmap() const { return m_bitmap
; }
109 virtual wxDataFormat
GetFormat() const { return wxDF_BITMAP
; }
111 // implement base class pure virtuals
112 virtual wxDataFormat
GetPreferredFormat() const
113 { return wxDF_BITMAP
; }
114 virtual bool IsSupportedFormat(wxDataFormat format
) const
115 { return format
== wxDF_BITMAP
; }
116 virtual size_t GetDataSize() const
117 { wxASSERT(FALSE
); return 0; } // BEMIMP
118 virtual void GetDataHere(void *pBuf
) const
119 { wxASSERT(FALSE
); } // BEMIMP
125 // ----------------------------------------------------------------------------
126 // wxMetaFileDataObject: see metafile.h is a specialization of wxDataObject for bitmap data
127 // ----------------------------------------------------------------------------
129 // TODO: wxFileDataObject.
131 #endif //_WX_OLEDATAOBJ_H