]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/ole/dataobj.h
converted to 16 colors
[wxWidgets.git] / include / wx / msw / ole / dataobj.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: 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_OLEDATAOBJ_H
13 #define _WX_OLEDATAOBJ_H
14
15 // ----------------------------------------------------------------------------
16 // wxDataFormat identifies the single format of data
17 // ----------------------------------------------------------------------------
18
19 class WXDLLEXPORT wxDataFormat
20 {
21 public:
22 // the clipboard formats under Win32 are UINTs
23 typedef unsigned int NativeFormat;
24
25 wxDataFormat(NativeFormat format = wxDF_INVALID) { m_format = format; }
26 wxDataFormat& operator=(NativeFormat format)
27 { m_format = format; return *this; }
28
29 // defautl copy ctor/assignment operators ok
30
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; }
40
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; }
46
47 // this only works with standard ids
48 void SetId(wxDataFormatId format) { m_format = format; }
49
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);
54
55 private:
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; }
58
59 NativeFormat m_format;
60 };
61
62 // ----------------------------------------------------------------------------
63 // forward declarations
64 // ----------------------------------------------------------------------------
65 struct IDataObject;
66
67 // ----------------------------------------------------------------------------
68 // wxDataObject is a "smart" and polymorphic piece of data.
69 //
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 // ----------------------------------------------------------------------------
74
75 class WXDLLEXPORT wxDataObject
76 {
77 public:
78 // function to return symbolic name of clipboard format (debug messages)
79 static const char *GetFormatName(wxDataFormat format);
80
81 // ctor & dtor
82 wxDataObject();
83 virtual ~wxDataObject();
84
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;
95
96 // accessors
97 // retrieve IDataObject interface (for other OLE related classes)
98 IDataObject *GetInterface() const { return m_pIDataObject; }
99
100 ////// wxGTK compatibility: hopefully to become the preferred API.
101 virtual wxDataFormat GetFormat() const { return GetPreferredFormat(); }
102
103 private:
104 IDataObject *m_pIDataObject; // pointer to the COM interface
105 };
106
107 // ----------------------------------------------------------------------------
108 // wxTextDataObject is a specialization of wxDataObject for text data
109 // ----------------------------------------------------------------------------
110 class WXDLLEXPORT wxTextDataObject : public wxDataObject
111 {
112 public:
113 // ctors
114 wxTextDataObject() { }
115 wxTextDataObject(const wxString& strText) : m_strText(strText) { }
116 void Init(const wxString& strText) { m_strText = strText; }
117
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()); }
127
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; }
132
133 private:
134 wxString m_strText;
135 };
136
137 // ----------------------------------------------------------------------------
138 // @@@ TODO: wx{Bitmap|Metafile|...}DataObject
139 // ----------------------------------------------------------------------------
140
141 // ----------------------------------------------------------------------------
142 // wxBitmapDataObject is a specialization of wxDataObject for bitmap data
143 // ----------------------------------------------------------------------------
144
145 // TODO: implement OLE side of things. At present, it's just for clipboard
146 // use.
147 class WXDLLEXPORT wxBitmapDataObject : public wxDataObject
148 {
149 public:
150 // ctors
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; }
155
156 virtual wxDataFormat GetFormat() const { return wxDF_BITMAP; }
157
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
167
168 private:
169 wxBitmap m_bitmap;
170 };
171
172 // ----------------------------------------------------------------------------
173 // wxMetaFileDataObject: see metafile.h is a specialization of wxDataObject for bitmap data
174 // ----------------------------------------------------------------------------
175
176 // TODO: wxFileDataObject.
177
178 #endif //_WX_OLEDATAOBJ_H
179