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 support
71 // SetData. We don't support all advise functions neither (but it's easy to
72 // do if we really want them)
73 // ----------------------------------------------------------------------------
75 class WXDLLEXPORT wxDataObject
78 // function to return symbolic name of clipboard format (debug messages)
79 static const char *GetFormatName(wxDataFormat format
);
83 virtual ~wxDataObject();
85 // pure virtuals to override
86 // get the best suited format for our data
87 virtual wxDataFormat
GetPreferredFormat() const = 0;
88 // decide if we support this format (should be one of values of
89 // wxDataFormatId enumerations or a user-defined format)
90 virtual bool IsSupportedFormat(wxDataFormat format
) const = 0;
91 // get the (total) size of data
92 virtual size_t GetDataSize() const = 0;
93 // copy raw data to provided pointer
94 virtual void GetDataHere(void *pBuf
) const = 0;
97 // retrieve IDataObject interface (for other OLE related classes)
98 IDataObject
*GetInterface() const { return m_pIDataObject
; }
100 ////// wxGTK compatibility: hopefully to become the preferred API.
101 virtual wxDataFormat
GetFormat() const { return GetPreferredFormat(); }
104 IDataObject
*m_pIDataObject
; // pointer to the COM interface
107 // ----------------------------------------------------------------------------
108 // wxTextDataObject is a specialization of wxDataObject for text data
109 // ----------------------------------------------------------------------------
110 class WXDLLEXPORT wxTextDataObject
: public wxDataObject
114 wxTextDataObject() { }
115 wxTextDataObject(const wxString
& strText
) : m_strText(strText
) { }
116 void Init(const wxString
& strText
) { m_strText
= strText
; }
118 // implement base class pure virtuals
119 virtual wxDataFormat
GetPreferredFormat() const
120 { return wxDF_TEXT
; }
121 virtual bool IsSupportedFormat(wxDataFormat format
) const
122 { return format
== wxDF_TEXT
|| format
== wxDF_LOCALE
; }
123 virtual size_t GetDataSize() const
124 { return m_strText
.Len() + 1; } // +1 for trailing '\0'of course
125 virtual void GetDataHere(void *pBuf
) const
126 { memcpy(pBuf
, m_strText
.c_str(), GetDataSize()); }
128 ////// wxGTK compatibility: hopefully to become the preferred API.
129 void SetText(const wxString
& strText
) { m_strText
= strText
; }
130 wxString
GetText() const { return m_strText
; }
131 virtual wxDataFormat
GetFormat() const { return wxDF_TEXT
; }
137 // ----------------------------------------------------------------------------
138 // @@@ TODO: wx{Bitmap|Metafile|...}DataObject
139 // ----------------------------------------------------------------------------
141 // ----------------------------------------------------------------------------
142 // wxBitmapDataObject is a specialization of wxDataObject for bitmap data
143 // ----------------------------------------------------------------------------
145 // TODO: implement OLE side of things. At present, it's just for clipboard
147 class WXDLLEXPORT wxBitmapDataObject
: public wxDataObject
151 wxBitmapDataObject() {};
152 wxBitmapDataObject(const wxBitmap
& bitmap
): m_bitmap(bitmap
) {}
153 void SetBitmap(const wxBitmap
& bitmap
) { m_bitmap
= bitmap
; }
154 wxBitmap
GetBitmap() const { return m_bitmap
; }
156 virtual wxDataFormat
GetFormat() const { return wxDF_BITMAP
; }
158 // implement base class pure virtuals
159 virtual wxDataFormat
GetPreferredFormat() const
160 { return wxDF_BITMAP
; }
161 virtual bool IsSupportedFormat(wxDataFormat format
) const
162 { return format
== wxDF_BITMAP
; }
163 virtual size_t GetDataSize() const
164 { wxASSERT(FALSE
); return 0; } // BEMIMP
165 virtual void GetDataHere(void *pBuf
) const
166 { wxASSERT(FALSE
); } // BEMIMP
172 // ----------------------------------------------------------------------------
173 // wxMetaFileDataObject: see metafile.h is a specialization of wxDataObject for bitmap data
174 // ----------------------------------------------------------------------------
176 // TODO: wxFileDataObject.
178 #endif //_WX_OLEDATAOBJ_H