wxDataObejct and related changes (won't compile right now)
[wxWidgets.git] / include / wx / msw / ole / dataobj.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/ole/dataobj.h
3 // Purpose: declaration of the wxDataObject class
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 10.05.98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_MSW_OLE_DATAOBJ_H
13 #define _WX_MSW_OLE_DATAOBJ_H
14
15 // ----------------------------------------------------------------------------
16 // forward declarations
17 // ----------------------------------------------------------------------------
18
19 struct IDataObject;
20
21 // ----------------------------------------------------------------------------
22 // wxDataObject is a "smart" and polymorphic piece of data.
23 // ----------------------------------------------------------------------------
24
25 class WXDLLEXPORT wxDataObject
26 {
27 public:
28 // ctor & dtor
29 wxDataObject();
30 virtual ~wxDataObject();
31
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
42 { return 1; }
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;
53
54 // accessors
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
58 // only one format
59 wxDataFormat GetFormat() const { return GetPreferredFormat(); }
60
61 // old interface
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;
65
66 // implementation only from now on
67 // -------------------------------
68
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
71 void SetAutoDelete();
72
73 #ifdef __WXDEBUG__
74 // function to return symbolic name of clipboard format (for debug messages)
75 static const char *GetFormatName(wxDataFormat format);
76 #endif // Debug
77
78 private:
79 IDataObject *m_pIDataObject; // pointer to the COM interface
80 };
81
82 // ----------------------------------------------------------------------------
83 // wxTextDataObject is a specialization of wxDataObject for text data
84 // ----------------------------------------------------------------------------
85
86 class WXDLLEXPORT wxTextDataObject : public wxDataObject
87 {
88 public:
89 // ctors
90 wxTextDataObject() { }
91 wxTextDataObject(const wxString& strText) : m_strText(strText) { }
92 void Init(const wxString& strText) { m_strText = strText; }
93
94 // implement base class pure virtuals
95 virtual wxDataFormat GetPreferredFormat() const
96 { return wxDF_TEXT; }
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; }
105
106 // additional helpers
107 void SetText(const wxString& strText) { m_strText = strText; }
108 wxString GetText() const { return m_strText; }
109
110 private:
111 wxString m_strText;
112 };
113
114 // ----------------------------------------------------------------------------
115 // wxBitmapDataObject is a specialization of wxDataObject for bitmap data
116 // ----------------------------------------------------------------------------
117
118 #include "wx/bitmap.h"
119
120 class WXDLLEXPORT wxBitmapDataObject : public wxDataObject
121 {
122 public:
123 // ctors
124 wxBitmapDataObject() { }
125 wxBitmapDataObject(const wxBitmap& bitmap): m_bitmap(bitmap) { }
126
127 // set/get our bitmap
128 void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; }
129 const wxBitmap GetBitmap() const { return m_bitmap; }
130
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);
139
140 private:
141 wxBitmap m_bitmap;
142 };
143
144 // ----------------------------------------------------------------------------
145 // wxMetaFileDataObject: see metafile.h is a specialization of wxDataObject for bitmap data
146 // ----------------------------------------------------------------------------
147
148 // TODO: wxFileDataObject.
149
150 #endif //_WX_MSW_OLE_DATAOBJ_H
151