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(const wxChar
*format
) { SetId(format
); }
28 wxDataFormat
& operator=(NativeFormat format
)
29 { m_format
= format
; return *this; }
30 wxDataFormat
& operator=(const wxDataFormat
& format
)
31 { m_format
= format
.m_format
; return *this; }
33 // defautl copy ctor/assignment operators ok
35 // comparison (must have both versions)
36 bool operator==(wxDataFormatId format
) const
37 { return m_format
== (NativeFormat
)format
; }
38 bool operator!=(wxDataFormatId format
) const
39 { return m_format
!= (NativeFormat
)format
; }
40 bool operator==(const wxDataFormat
& format
) const
41 { return m_format
== format
.m_format
; }
42 bool operator!=(const wxDataFormat
& format
) const
43 { return m_format
!= format
.m_format
; }
45 // explicit and implicit conversions to NativeFormat which is one of
46 // standard data types (implicit conversion is useful for preserving the
47 // compatibility with old code)
48 NativeFormat
GetFormatId() const { return m_format
; }
49 operator NativeFormat() const { return m_format
; }
51 // this only works with standard ids
52 void SetId(wxDataFormatId format
) { m_format
= format
; }
54 // string ids are used for custom types - this SetId() must be used for
55 // application-specific formats
56 wxString
GetId() const;
57 void SetId(const wxChar
*format
);
60 // returns TRUE if the format is one of those defined in wxDataFormatId
61 bool IsStandard() const { return m_format
> 0 && m_format
< wxDF_MAX
; }
63 NativeFormat m_format
;
66 // ----------------------------------------------------------------------------
67 // forward declarations
68 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
73 // wxDataObject is a "smart" and polymorphic piece of data.
74 // ----------------------------------------------------------------------------
76 class WXDLLEXPORT wxDataObject
81 virtual ~wxDataObject();
83 // pure virtuals to override
84 // get the best suited format for rendering our data
85 virtual wxDataFormat
GetPreferredFormat() const = 0;
86 // get the number of formats we support: it is understood that if we
87 // can accept data in some format, then we can render data in this
88 // format as well, but the contrary is not necessarily true. For the
89 // default value of the argument, all formats we support should be
90 // returned, but if outputOnlyToo == FALSE, then we should only return
91 // the formats which our SetData() understands
92 virtual size_t GetFormatCount(bool outputOnlyToo
= TRUE
) const
94 // return all formats in the provided array (of size GetFormatCount())
95 virtual void GetAllFormats(wxDataFormat
*formats
,
96 bool outputOnlyToo
= TRUE
) const
97 { formats
[0] = GetPreferredFormat(); }
98 // get the (total) size of data for the given format
99 virtual size_t GetDataSize(const wxDataFormat
& format
) const = 0;
100 // copy raw data (in the specified format) to provided pointer
101 virtual bool GetDataHere(const wxDataFormat
& format
, void *buf
) const = 0;
102 // get data from the buffer (in the given format)
103 virtual bool SetData(const wxDataFormat
& format
, const void *buf
) = 0;
106 // retrieve IDataObject interface (for other OLE related classes)
107 IDataObject
*GetInterface() const { return m_pIDataObject
; }
108 // a simpler name which makes more sense for data objects supporting
110 wxDataFormat
GetFormat() const { return GetPreferredFormat(); }
113 // decide if we support this format (can be either standard or custom
114 // format) -- now uses GetAllFormats()
115 virtual bool IsSupportedFormat(const wxDataFormat
& format
) const;
117 // implementation only from now on
118 // -------------------------------
120 // tell the object that it should be now owned by IDataObject - i.e. when
121 // it is deleted, it should delete us as well
122 void SetAutoDelete();
125 // function to return symbolic name of clipboard format (for debug messages)
126 static const char *GetFormatName(wxDataFormat format
);
130 IDataObject
*m_pIDataObject
; // pointer to the COM interface
133 // ----------------------------------------------------------------------------
134 // wxTextDataObject is a specialization of wxDataObject for text data
135 // ----------------------------------------------------------------------------
137 class WXDLLEXPORT wxTextDataObject
: public wxDataObject
141 wxTextDataObject() { }
142 wxTextDataObject(const wxString
& strText
) : m_strText(strText
) { }
143 void Init(const wxString
& strText
) { m_strText
= strText
; }
145 // implement base class pure virtuals
146 virtual wxDataFormat
GetPreferredFormat() const
147 { return wxDF_TEXT
; }
148 virtual bool IsSupportedFormat(const wxDataFormat
& format
) const
149 { return format
== wxDF_TEXT
|| format
== wxDF_LOCALE
; }
150 virtual size_t GetDataSize(const wxDataFormat
& format
) const
151 { return m_strText
.Len() + 1; } // +1 for trailing '\0'of course
152 virtual bool GetDataHere(const wxDataFormat
& format
, void *buf
) const
153 { memcpy(buf
, m_strText
.c_str(), GetDataSize(format
)); return TRUE
; }
154 virtual bool SetData(const wxDataFormat
& format
, const void *buf
)
155 { m_strText
= (const wxChar
*)buf
; return TRUE
; }
157 // additional helpers
158 void SetText(const wxString
& strText
) { m_strText
= strText
; }
159 wxString
GetText() const { return m_strText
; }
165 // ----------------------------------------------------------------------------
166 // wxBitmapDataObject is a specialization of wxDataObject for bitmap data
167 // ----------------------------------------------------------------------------
169 #include "wx/bitmap.h"
171 class WXDLLEXPORT wxBitmapDataObject
: public wxDataObject
175 wxBitmapDataObject() { }
176 wxBitmapDataObject(const wxBitmap
& bitmap
): m_bitmap(bitmap
) { }
178 // set/get our bitmap
179 void SetBitmap(const wxBitmap
& bitmap
) { m_bitmap
= bitmap
; }
180 const wxBitmap
GetBitmap() const { return m_bitmap
; }
182 // implement base class pure virtuals
183 virtual wxDataFormat
GetPreferredFormat() const { return wxDF_BITMAP
; }
184 virtual size_t GetFormatCount(bool outputOnlyToo
= TRUE
) const;
185 virtual void GetAllFormats(wxDataFormat
*formats
,
186 bool outputOnlyToo
= TRUE
) const;
187 virtual size_t GetDataSize(const wxDataFormat
& format
) const;
188 virtual bool GetDataHere(const wxDataFormat
& format
, void *buf
) const;
189 virtual bool SetData(const wxDataFormat
& format
, const void *buf
);
195 // ----------------------------------------------------------------------------
196 // wxMetaFileDataObject: see metafile.h is a specialization of wxDataObject for bitmap data
197 // ----------------------------------------------------------------------------
199 // TODO: wxFileDataObject.
201 #endif //_WX_OLEDATAOBJ_H