1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/ole/dataobj.h
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_MSW_OLE_DATAOBJ_H
13 #define _WX_MSW_OLE_DATAOBJ_H
15 // ----------------------------------------------------------------------------
16 // forward declarations
17 // ----------------------------------------------------------------------------
21 // ----------------------------------------------------------------------------
22 // wxDataObject is a "smart" and polymorphic piece of data.
23 // ----------------------------------------------------------------------------
25 class WXDLLEXPORT wxDataObject
30 virtual ~wxDataObject();
32 // pure virtuals to override
33 // get the best suited format for rendering our data
34 virtual wxDataFormat
GetPreferredFormat() const = 0;
35 // get the number of formats we support: it is understood that if we
36 // can accept data in some format, then we can render data in this
37 // format as well, but the contrary is not necessarily true. For the
38 // default value of the argument, all formats we support should be
39 // returned, but if outputOnlyToo == FALSE, then we should only return
40 // the formats which our SetData() understands
41 virtual size_t GetFormatCount(bool outputOnlyToo
= TRUE
) const
43 // return all formats in the provided array (of size GetFormatCount())
44 virtual void GetAllFormats(wxDataFormat
*formats
,
45 bool outputOnlyToo
= TRUE
) const
46 { formats
[0] = GetPreferredFormat(); }
47 // get the (total) size of data for the given format
48 virtual size_t GetDataSize(const wxDataFormat
& format
) const = 0;
49 // copy raw data (in the specified format) to provided pointer
50 virtual bool GetDataHere(const wxDataFormat
& format
, void *buf
) const = 0;
51 // get data from the buffer (in the given format)
52 virtual bool SetData(const wxDataFormat
& format
, const void *buf
) = 0;
55 // retrieve IDataObject interface (for other OLE related classes)
56 IDataObject
*GetInterface() const { return m_pIDataObject
; }
57 // a simpler name which makes more sense for data objects supporting
59 wxDataFormat
GetFormat() const { return GetPreferredFormat(); }
62 // decide if we support this format (can be either standard or custom
63 // format) -- now uses GetAllFormats()
64 virtual bool IsSupportedFormat(const wxDataFormat
& format
) const;
66 // implementation only from now on
67 // -------------------------------
69 // tell the object that it should be now owned by IDataObject - i.e. when
70 // it is deleted, it should delete us as well
74 // function to return symbolic name of clipboard format (for debug messages)
75 static const char *GetFormatName(wxDataFormat format
);
79 IDataObject
*m_pIDataObject
; // pointer to the COM interface
82 // ----------------------------------------------------------------------------
83 // wxTextDataObject is a specialization of wxDataObject for text data
84 // ----------------------------------------------------------------------------
86 class WXDLLEXPORT wxTextDataObject
: public wxDataObject
90 wxTextDataObject() { }
91 wxTextDataObject(const wxString
& strText
) : m_strText(strText
) { }
92 void Init(const wxString
& strText
) { m_strText
= strText
; }
94 // implement base class pure virtuals
95 virtual wxDataFormat
GetPreferredFormat() const
97 virtual bool IsSupportedFormat(const wxDataFormat
& format
) const
98 { return format
== wxDF_TEXT
|| format
== wxDF_LOCALE
; }
99 virtual size_t GetDataSize(const wxDataFormat
& format
) const
100 { return m_strText
.Len() + 1; } // +1 for trailing '\0'of course
101 virtual bool GetDataHere(const wxDataFormat
& format
, void *buf
) const
102 { memcpy(buf
, m_strText
.c_str(), GetDataSize(format
)); return TRUE
; }
103 virtual bool SetData(const wxDataFormat
& format
, const void *buf
)
104 { m_strText
= (const wxChar
*)buf
; return TRUE
; }
106 // additional helpers
107 void SetText(const wxString
& strText
) { m_strText
= strText
; }
108 wxString
GetText() const { return m_strText
; }
114 // ----------------------------------------------------------------------------
115 // wxBitmapDataObject is a specialization of wxDataObject for bitmap data
116 // ----------------------------------------------------------------------------
118 #include "wx/bitmap.h"
120 class WXDLLEXPORT wxBitmapDataObject
: public wxDataObject
124 wxBitmapDataObject() { }
125 wxBitmapDataObject(const wxBitmap
& bitmap
): m_bitmap(bitmap
) { }
127 // set/get our bitmap
128 void SetBitmap(const wxBitmap
& bitmap
) { m_bitmap
= bitmap
; }
129 const wxBitmap
GetBitmap() const { return m_bitmap
; }
131 // implement base class pure virtuals
132 virtual wxDataFormat
GetPreferredFormat() const { return wxDF_BITMAP
; }
133 virtual size_t GetFormatCount(bool outputOnlyToo
= TRUE
) const;
134 virtual void GetAllFormats(wxDataFormat
*formats
,
135 bool outputOnlyToo
= TRUE
) const;
136 virtual size_t GetDataSize(const wxDataFormat
& format
) const;
137 virtual bool GetDataHere(const wxDataFormat
& format
, void *buf
) const;
138 virtual bool SetData(const wxDataFormat
& format
, const void *buf
);
144 // ----------------------------------------------------------------------------
145 // wxMetaFileDataObject: see metafile.h is a specialization of wxDataObject for bitmap data
146 // ----------------------------------------------------------------------------
148 // TODO: wxFileDataObject.
150 #endif //_WX_MSW_OLE_DATAOBJ_H