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 #include "wx/bitmap.h"
16 // ----------------------------------------------------------------------------
17 // wxDataFormat identifies the single format of data
18 // ----------------------------------------------------------------------------
20 class WXDLLEXPORT wxDataFormat
23 // the clipboard formats under Win32 are UINTs
24 typedef unsigned int NativeFormat
;
26 wxDataFormat(NativeFormat format
= wxDF_INVALID
) { m_format
= format
; }
27 wxDataFormat
& operator=(NativeFormat format
)
28 { m_format
= format
; return *this; }
30 // defautl copy ctor/assignment operators ok
32 // comparison (must have both versions)
33 bool operator==(wxDataFormatId format
) const
34 { return m_format
== (NativeFormat
)format
; }
35 bool operator!=(wxDataFormatId format
) const
36 { return m_format
!= (NativeFormat
)format
; }
37 bool operator==(const wxDataFormat
& format
) const
38 { return m_format
== format
.m_format
; }
39 bool operator!=(const wxDataFormat
& format
) const
40 { return m_format
!= format
.m_format
; }
42 // explicit and implicit conversions to NativeFormat which is one of
43 // standard data types (implicit conversion is useful for preserving the
44 // compatibility with old code)
45 NativeFormat
GetFormatId() const { return m_format
; }
46 operator NativeFormat() const { return m_format
; }
48 // this only works with standard ids
49 void SetId(wxDataFormatId format
) { m_format
= format
; }
51 // string ids are used for custom types - this SetId() must be used for
52 // application-specific formats
53 wxString
GetId() const;
54 void SetId(const wxChar
*format
);
57 // returns TRUE if the format is one of those defined in wxDataFormatId
58 bool IsStandard() const { return m_format
> 0 && m_format
< wxDF_MAX
; }
60 NativeFormat m_format
;
63 // ----------------------------------------------------------------------------
64 // forward declarations
65 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
69 // wxDataObject is a "smart" and polymorphic piece of data.
71 // TODO it's currently "read-only" from COM point of view, i.e. we don't support
72 // SetData. We don't support all advise functions neither (but it's easy to
73 // do if we really want them)
74 // ----------------------------------------------------------------------------
76 class WXDLLEXPORT wxDataObject
79 // function to return symbolic name of clipboard format (debug messages)
80 static const char *GetFormatName(wxDataFormat format
);
84 virtual ~wxDataObject();
86 // pure virtuals to override
87 // get the best suited format for our data
88 virtual wxDataFormat
GetPreferredFormat() const = 0;
89 // decide if we support this format (should be one of values of
90 // wxDataFormatId enumerations or a user-defined format)
91 virtual bool IsSupportedFormat(wxDataFormat format
) const = 0;
92 // get the (total) size of data
93 virtual size_t GetDataSize() const = 0;
94 // copy raw data to provided pointer
95 virtual void GetDataHere(void *pBuf
) const = 0;
98 // retrieve IDataObject interface (for other OLE related classes)
99 IDataObject
*GetInterface() const { return m_pIDataObject
; }
101 ////// wxGTK compatibility: hopefully to become the preferred API.
102 virtual wxDataFormat
GetFormat() const { return GetPreferredFormat(); }
105 IDataObject
*m_pIDataObject
; // pointer to the COM interface
108 // ----------------------------------------------------------------------------
109 // wxTextDataObject is a specialization of wxDataObject for text data
110 // ----------------------------------------------------------------------------
111 class WXDLLEXPORT wxTextDataObject
: public wxDataObject
115 wxTextDataObject() { }
116 wxTextDataObject(const wxString
& strText
) : m_strText(strText
) { }
117 void Init(const wxString
& strText
) { m_strText
= strText
; }
119 // implement base class pure virtuals
120 virtual wxDataFormat
GetPreferredFormat() const
121 { return wxDF_TEXT
; }
122 virtual bool IsSupportedFormat(wxDataFormat format
) const
123 { return format
== wxDF_TEXT
|| format
== wxDF_LOCALE
; }
124 virtual size_t GetDataSize() const
125 { return m_strText
.Len() + 1; } // +1 for trailing '\0'of course
126 virtual void GetDataHere(void *pBuf
) const
127 { memcpy(pBuf
, m_strText
.c_str(), GetDataSize()); }
129 ////// wxGTK compatibility: hopefully to become the preferred API.
130 void SetText(const wxString
& strText
) { m_strText
= strText
; }
131 wxString
GetText() const { return m_strText
; }
132 virtual wxDataFormat
GetFormat() const { return wxDF_TEXT
; }
138 // ----------------------------------------------------------------------------
139 // @@@ TODO: wx{Bitmap|Metafile|...}DataObject
140 // ----------------------------------------------------------------------------
142 // ----------------------------------------------------------------------------
143 // wxBitmapDataObject is a specialization of wxDataObject for bitmap data
144 // ----------------------------------------------------------------------------
146 // TODO: implement OLE side of things. At present, it's just for clipboard
148 class WXDLLEXPORT wxBitmapDataObject
: public wxDataObject
152 wxBitmapDataObject() {}
153 wxBitmapDataObject(const wxBitmap
& bitmap
): m_bitmap(bitmap
) {}
154 void SetBitmap(const wxBitmap
& bitmap
) { m_bitmap
= bitmap
; }
155 wxBitmap
GetBitmap() const { return m_bitmap
; }
157 virtual wxDataFormat
GetFormat() const { return wxDF_BITMAP
; }
159 // implement base class pure virtuals
160 virtual wxDataFormat
GetPreferredFormat() const
161 { return wxDF_BITMAP
; }
162 virtual bool IsSupportedFormat(wxDataFormat format
) const
163 { return format
== wxDF_BITMAP
; }
164 virtual size_t GetDataSize() const
165 { wxASSERT(FALSE
); return 0; } // BEMIMP
166 virtual void GetDataHere(void *pBuf
) const
167 { wxASSERT(FALSE
); } // BEMIMP
173 // ----------------------------------------------------------------------------
174 // wxMetaFileDataObject: see metafile.h is a specialization of wxDataObject for bitmap data
175 // ----------------------------------------------------------------------------
177 // TODO: wxFileDataObject.
179 #endif //_WX_OLEDATAOBJ_H