]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/ole/dataobj.h
Solved problem with wxhInstance name being mangled by MSVC; wxGetInstance is now...
[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 #include "wx/bitmap.h"
16 // ----------------------------------------------------------------------------
17 // wxDataFormat identifies the single format of data
18 // ----------------------------------------------------------------------------
19
20 class WXDLLEXPORT wxDataFormat
21 {
22 public:
23 // the clipboard formats under Win32 are UINTs
24 typedef unsigned int NativeFormat;
25
26 wxDataFormat(NativeFormat format = wxDF_INVALID) { m_format = format; }
27 wxDataFormat& operator=(NativeFormat format)
28 { m_format = format; return *this; }
29
30 // defautl copy ctor/assignment operators ok
31
32 // comparison (must have both versions)
33 bool operator==(wxDataFormatId format) const
34 { return m_format == (NativeFormat)format; }
35 bool operator!=(wxDataFormatId format) const
36 { return m_format != (NativeFormat)format; }
37 bool operator==(const wxDataFormat& format) const
38 { return m_format == format.m_format; }
39 bool operator!=(const wxDataFormat& format) const
40 { return m_format != format.m_format; }
41
42 // explicit and implicit conversions to NativeFormat which is one of
43 // standard data types (implicit conversion is useful for preserving the
44 // compatibility with old code)
45 NativeFormat GetFormatId() const { return m_format; }
46 operator NativeFormat() const { return m_format; }
47
48 // this only works with standard ids
49 void SetId(wxDataFormatId format) { m_format = format; }
50
51 // string ids are used for custom types - this SetId() must be used for
52 // application-specific formats
53 wxString GetId() const;
54 void SetId(const wxChar *format);
55
56 private:
57 // returns TRUE if the format is one of those defined in wxDataFormatId
58 bool IsStandard() const { return m_format > 0 && m_format < wxDF_MAX; }
59
60 NativeFormat m_format;
61 };
62
63 // ----------------------------------------------------------------------------
64 // forward declarations
65 // ----------------------------------------------------------------------------
66 struct IDataObject;
67
68 // ----------------------------------------------------------------------------
69 // wxDataObject is a "smart" and polymorphic piece of data.
70 //
71 // TODO it's currently "read-only" from COM point of view, i.e. we don't support
72 // SetData. We don't support all advise functions neither (but it's easy to
73 // do if we really want them)
74 // ----------------------------------------------------------------------------
75
76 class WXDLLEXPORT wxDataObject
77 {
78 public:
79 // function to return symbolic name of clipboard format (debug messages)
80 static const char *GetFormatName(wxDataFormat format);
81
82 // ctor & dtor
83 wxDataObject();
84 virtual ~wxDataObject();
85
86 // pure virtuals to override
87 // get the best suited format for our data
88 virtual wxDataFormat GetPreferredFormat() const = 0;
89 // decide if we support this format (should be one of values of
90 // wxDataFormatId enumerations or a user-defined format)
91 virtual bool IsSupportedFormat(wxDataFormat format) const = 0;
92 // get the (total) size of data
93 virtual size_t GetDataSize() const = 0;
94 // copy raw data to provided pointer
95 virtual void GetDataHere(void *pBuf) const = 0;
96
97 // accessors
98 // retrieve IDataObject interface (for other OLE related classes)
99 IDataObject *GetInterface() const { return m_pIDataObject; }
100
101 ////// wxGTK compatibility: hopefully to become the preferred API.
102 virtual wxDataFormat GetFormat() const { return GetPreferredFormat(); }
103
104 private:
105 IDataObject *m_pIDataObject; // pointer to the COM interface
106 };
107
108 // ----------------------------------------------------------------------------
109 // wxTextDataObject is a specialization of wxDataObject for text data
110 // ----------------------------------------------------------------------------
111 class WXDLLEXPORT wxTextDataObject : public wxDataObject
112 {
113 public:
114 // ctors
115 wxTextDataObject() { }
116 wxTextDataObject(const wxString& strText) : m_strText(strText) { }
117 void Init(const wxString& strText) { m_strText = strText; }
118
119 // implement base class pure virtuals
120 virtual wxDataFormat GetPreferredFormat() const
121 { return wxDF_TEXT; }
122 virtual bool IsSupportedFormat(wxDataFormat format) const
123 { return format == wxDF_TEXT || format == wxDF_LOCALE; }
124 virtual size_t GetDataSize() const
125 { return m_strText.Len() + 1; } // +1 for trailing '\0'of course
126 virtual void GetDataHere(void *pBuf) const
127 { memcpy(pBuf, m_strText.c_str(), GetDataSize()); }
128
129 ////// wxGTK compatibility: hopefully to become the preferred API.
130 void SetText(const wxString& strText) { m_strText = strText; }
131 wxString GetText() const { return m_strText; }
132 virtual wxDataFormat GetFormat() const { return wxDF_TEXT; }
133
134 private:
135 wxString m_strText;
136 };
137
138 // ----------------------------------------------------------------------------
139 // @@@ TODO: wx{Bitmap|Metafile|...}DataObject
140 // ----------------------------------------------------------------------------
141
142 // ----------------------------------------------------------------------------
143 // wxBitmapDataObject is a specialization of wxDataObject for bitmap data
144 // ----------------------------------------------------------------------------
145
146 // TODO: implement OLE side of things. At present, it's just for clipboard
147 // use.
148 class WXDLLEXPORT wxBitmapDataObject : public wxDataObject
149 {
150 public:
151 // ctors
152 wxBitmapDataObject() {}
153 wxBitmapDataObject(const wxBitmap& bitmap): m_bitmap(bitmap) {}
154 void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; }
155 wxBitmap GetBitmap() const { return m_bitmap; }
156
157 virtual wxDataFormat GetFormat() const { return wxDF_BITMAP; }
158
159 // implement base class pure virtuals
160 virtual wxDataFormat GetPreferredFormat() const
161 { return wxDF_BITMAP; }
162 virtual bool IsSupportedFormat(wxDataFormat format) const
163 { return format == wxDF_BITMAP; }
164 virtual size_t GetDataSize() const
165 { wxASSERT(FALSE); return 0; } // BEMIMP
166 virtual void GetDataHere(void *pBuf) const
167 { wxASSERT(FALSE); } // BEMIMP
168
169 private:
170 wxBitmap m_bitmap;
171 };
172
173 // ----------------------------------------------------------------------------
174 // wxMetaFileDataObject: see metafile.h is a specialization of wxDataObject for bitmap data
175 // ----------------------------------------------------------------------------
176
177 // TODO: wxFileDataObject.
178
179 #endif //_WX_OLEDATAOBJ_H
180