]>
Commit | Line | Data |
---|---|---|
1737035f VZ |
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> | |
bbcdf8bc | 9 | // Licence: wxWindows licence |
1737035f VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
bbcdf8bc JS |
12 | #ifndef _WX_OLEDATAOBJ_H |
13 | #define _WX_OLEDATAOBJ_H | |
1737035f | 14 | |
da175b2c RR |
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 | ||
1737035f VZ |
62 | // ---------------------------------------------------------------------------- |
63 | // forward declarations | |
64 | // ---------------------------------------------------------------------------- | |
65 | struct IDataObject; | |
66 | ||
67 | // ---------------------------------------------------------------------------- | |
68 | // wxDataObject is a "smart" and polymorphic piece of data. | |
69 | // | |
3f480da3 VZ |
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) | |
1737035f VZ |
73 | // ---------------------------------------------------------------------------- |
74 | ||
8853b9a8 | 75 | class WXDLLEXPORT wxDataObject |
1737035f VZ |
76 | { |
77 | public: | |
40e1a9c0 JS |
78 | // function to return symbolic name of clipboard format (debug messages) |
79 | static const char *GetFormatName(wxDataFormat format); | |
1737035f VZ |
80 | |
81 | // ctor & dtor | |
82 | wxDataObject(); | |
25889d3c | 83 | virtual ~wxDataObject(); |
1737035f VZ |
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 | |
3f480da3 | 89 | // wxDataFormatId enumerations or a user-defined format) |
1737035f VZ |
90 | virtual bool IsSupportedFormat(wxDataFormat format) const = 0; |
91 | // get the (total) size of data | |
3cda6353 | 92 | virtual size_t GetDataSize() const = 0; |
1737035f VZ |
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 | ||
06e43511 JS |
100 | ////// wxGTK compatibility: hopefully to become the preferred API. |
101 | virtual wxDataFormat GetFormat() const { return GetPreferredFormat(); } | |
102 | ||
1737035f VZ |
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 | // ---------------------------------------------------------------------------- | |
8853b9a8 | 110 | class WXDLLEXPORT wxTextDataObject : public wxDataObject |
1737035f VZ |
111 | { |
112 | public: | |
113 | // ctors | |
26f86486 | 114 | wxTextDataObject() { } |
1737035f VZ |
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 | |
3f480da3 | 120 | { return wxDF_TEXT; } |
1737035f | 121 | virtual bool IsSupportedFormat(wxDataFormat format) const |
3f480da3 | 122 | { return format == wxDF_TEXT || format == wxDF_LOCALE; } |
3cda6353 | 123 | virtual size_t GetDataSize() const |
1737035f VZ |
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 | ||
06e43511 JS |
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 | ||
1737035f VZ |
133 | private: |
134 | wxString m_strText; | |
135 | }; | |
136 | ||
137 | // ---------------------------------------------------------------------------- | |
138 | // @@@ TODO: wx{Bitmap|Metafile|...}DataObject | |
139 | // ---------------------------------------------------------------------------- | |
140 | ||
06e43511 JS |
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 | ||
06e43511 JS |
158 | // implement base class pure virtuals |
159 | virtual wxDataFormat GetPreferredFormat() const | |
3f480da3 | 160 | { return wxDF_BITMAP; } |
06e43511 | 161 | virtual bool IsSupportedFormat(wxDataFormat format) const |
3f480da3 | 162 | { return format == wxDF_BITMAP; } |
06e43511 | 163 | virtual size_t GetDataSize() const |
25889d3c | 164 | { wxASSERT(FALSE); return 0; } // BEMIMP |
06e43511 | 165 | virtual void GetDataHere(void *pBuf) const |
25889d3c | 166 | { wxASSERT(FALSE); } // BEMIMP |
06e43511 JS |
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 | ||
657865d2 | 176 | // TODO: wxFileDataObject. |
2845ddc2 | 177 | |
bbcdf8bc | 178 | #endif //_WX_OLEDATAOBJ_H |
06e43511 | 179 |