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 // wxDataFormat identifies the single format of data
17 // ----------------------------------------------------------------------------
19 class WXDLLEXPORT wxDataFormat
22 // the clipboard formats under Win32 are UINTs
23 typedef unsigned int NativeFormat
;
25 wxDataFormat(NativeFormat format
= wxDF_INVALID
) { m_format
= format
; }
26 wxDataFormat
& operator=(NativeFormat format
)
27 { m_format
= format
; return *this; }
29 // defautl copy ctor/assignment operators ok
31 // comparison (must have both versions)
32 bool operator==(wxDataFormatId format
) const
33 { return m_format
== (NativeFormat
)format
; }
34 bool operator!=(wxDataFormatId format
) const
35 { return m_format
!= (NativeFormat
)format
; }
36 bool operator==(const wxDataFormat
& format
) const
37 { return m_format
== format
.m_format
; }
38 bool operator!=(const wxDataFormat
& format
) const
39 { return m_format
!= format
.m_format
; }
41 // explicit and implicit conversions to NativeFormat which is one of
42 // standard data types (implicit conversion is useful for preserving the
43 // compatibility with old code)
44 NativeFormat
GetFormatId() const { return m_format
; }
45 operator NativeFormat() const { return m_format
; }
47 // this only works with standard ids
48 void SetId(wxDataFormatId format
) { m_format
= format
; }
50 // string ids are used for custom types - this SetId() must be used for
51 // application-specific formats
52 wxString
GetId() const;
53 void SetId(const wxChar
*format
);
56 // returns TRUE if the format is one of those defined in wxDataFormatId
57 bool IsStandard() const { return m_format
> 0 && m_format
< wxDF_MAX
; }
59 NativeFormat m_format
;
62 // ----------------------------------------------------------------------------
63 // forward declarations
64 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
68 // wxDataObject is a "smart" and polymorphic piece of data.
70 // TODO it's currently "read-only" from COM point of view, i.e. we don't
71 // support SetData. We don't support all advise functions neither (but
72 // it's easy to do if we really want them)
73 // ----------------------------------------------------------------------------
75 class WXDLLEXPORT wxDataObject
80 virtual ~wxDataObject();
82 // pure virtuals to override
83 // get the best suited format for our data
84 virtual wxDataFormat
GetPreferredFormat() const = 0;
85 // get the number of formats we support
86 virtual size_t GetFormatCount() const
88 // return all formats in the provided array (of size GetFormatCount())
89 virtual void GetAllFormats(wxDataFormat
*formats
) const
90 { formats
[0] = GetPreferredFormat(); }
91 // get the (total) size of data for the given format
92 virtual size_t GetDataSize(const wxDataFormat
& format
) const = 0;
93 // copy raw data (in the specified format) to provided pointer
94 virtual void GetDataHere(const wxDataFormat
& format
, void *pBuf
) const = 0;
97 // retrieve IDataObject interface (for other OLE related classes)
98 IDataObject
*GetInterface() const { return m_pIDataObject
; }
99 // a simpler name which makes more sense for data objects supporting
101 wxDataFormat
GetFormat() const { return GetPreferredFormat(); }
104 // decide if we support this format (can be either standard or custom
105 // format) -- now uses GetAllFormats()
106 virtual bool IsSupportedFormat(const wxDataFormat
& format
) const;
109 // function to return symbolic name of clipboard format (for debug messages)
110 static const char *GetFormatName(wxDataFormat format
);
114 IDataObject
*m_pIDataObject
; // pointer to the COM interface
117 // ----------------------------------------------------------------------------
118 // wxTextDataObject is a specialization of wxDataObject for text data
119 // ----------------------------------------------------------------------------
121 class WXDLLEXPORT wxTextDataObject
: public wxDataObject
125 wxTextDataObject() { }
126 wxTextDataObject(const wxString
& strText
) : m_strText(strText
) { }
127 void Init(const wxString
& strText
) { m_strText
= strText
; }
129 // implement base class pure virtuals
130 virtual wxDataFormat
GetPreferredFormat() const
131 { return wxDF_TEXT
; }
132 virtual bool IsSupportedFormat(const wxDataFormat
& format
) const
133 { return format
== wxDF_TEXT
|| format
== wxDF_LOCALE
; }
134 virtual size_t GetDataSize(const wxDataFormat
& format
) const
135 { return m_strText
.Len() + 1; } // +1 for trailing '\0'of course
136 virtual void GetDataHere(const wxDataFormat
& format
, void *pBuf
) const
137 { memcpy(pBuf
, m_strText
.c_str(), GetDataSize(format
)); }
139 // additional helpers
140 void SetText(const wxString
& strText
) { m_strText
= strText
; }
141 wxString
GetText() const { return m_strText
; }
147 // ----------------------------------------------------------------------------
148 // TODO: wx{Bitmap|Metafile|...}DataObject
149 // ----------------------------------------------------------------------------
151 // ----------------------------------------------------------------------------
152 // wxBitmapDataObject is a specialization of wxDataObject for bitmap data
153 // ----------------------------------------------------------------------------
155 // TODO: implement OLE side of things. At present, it's just for clipboard
157 #include "wx/bitmap.h"
159 class WXDLLEXPORT wxBitmapDataObject
: public wxDataObject
163 wxBitmapDataObject() { }
164 wxBitmapDataObject(const wxBitmap
& bitmap
): m_bitmap(bitmap
) { }
166 // set/get our bitmap
167 void SetBitmap(const wxBitmap
& bitmap
) { m_bitmap
= bitmap
; }
168 const wxBitmap
GetBitmap() const { return m_bitmap
; }
170 // implement base class pure virtuals
171 virtual wxDataFormat
GetPreferredFormat() const
172 { return wxDF_BITMAP
; }
173 virtual bool IsSupportedFormat(const wxDataFormat
& format
) const
174 { return format
== wxDF_BITMAP
; }
175 virtual size_t GetDataSize(const wxDataFormat
& format
) const;
176 virtual void GetDataHere(const wxDataFormat
& format
, void *pBuf
) const;
182 // ----------------------------------------------------------------------------
183 // wxMetaFileDataObject: see metafile.h is a specialization of wxDataObject for bitmap data
184 // ----------------------------------------------------------------------------
186 // TODO: wxFileDataObject.
188 #endif //_WX_OLEDATAOBJ_H