]>
Commit | Line | Data |
---|---|---|
8b53e5a2 RR |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: dataobj.h | |
3 | // Purpose: declaration of the wxDataObject class | |
4 | // Author: Robert Roebling | |
5 | // RCS-ID: $Id$ | |
6 | // Copyright: (c) 1998 Vadim Zeitlin, Robert Roebling | |
7 | // Licence: wxWindows license | |
8 | /////////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifndef __GTKDATAOBJECTH__ | |
11 | #define __GTKDATAOBJECTH__ | |
12 | ||
13 | #ifdef __GNUG__ | |
14 | #pragma interface | |
15 | #endif | |
16 | ||
17 | #include "wx/defs.h" | |
18 | #include "wx/object.h" | |
19 | #include "wx/string.h" | |
20 | #include "wx/bitmap.h" | |
21 | ||
22 | //------------------------------------------------------------------------- | |
23 | // classes | |
24 | //------------------------------------------------------------------------- | |
25 | ||
0d2a2b60 RR |
26 | class wxDataFormat; |
27 | class wxDataBroker; | |
8b53e5a2 RR |
28 | class wxDataObject; |
29 | class wxTextDataObject; | |
30 | class wxBitmapDataObject; | |
31 | class wxPrivateDataObject; | |
32 | class wxFileDataObject; | |
33 | ||
f37615d7 | 34 | //------------------------------------------------------------------------- |
1dd989e1 | 35 | // wxDataFormat |
f37615d7 RR |
36 | //------------------------------------------------------------------------- |
37 | ||
1dd989e1 | 38 | class wxDataFormat |
0d2a2b60 | 39 | { |
8b53e5a2 | 40 | public: |
1dd989e1 RR |
41 | // the clipboard formats under GDK are GdkAtoms |
42 | typedef GdkAtom NativeFormat; | |
43 | ||
3f480da3 VZ |
44 | wxDataFormat(); |
45 | wxDataFormat( wxDataFormatId type ); | |
46 | wxDataFormat( const wxString &id ); | |
47 | wxDataFormat( const wxChar *id ); | |
1dd989e1 RR |
48 | wxDataFormat( NativeFormat format ); |
49 | ||
50 | wxDataFormat& operator=(NativeFormat format) | |
51 | { SetId(format); return *this; } | |
52 | wxDataFormat& operator=(const wxDataFormat& format) | |
53 | { SetId(format); return *this; } | |
54 | ||
55 | // comparison (must have both versions) | |
56 | bool operator==(wxDataFormatId type) const | |
57 | { return m_type == (wxDataFormatId)type; } | |
58 | bool operator!=(wxDataFormatId type) const | |
59 | { return m_type != (wxDataFormatId)type; } | |
60 | bool operator==(NativeFormat format) const | |
61 | { return m_format == (NativeFormat)format; } | |
62 | bool operator!=(NativeFormat format) const | |
63 | { return m_format != (NativeFormat)format; } | |
64 | bool operator==(const wxDataFormat& format) const | |
65 | { return m_format == format.m_format; } | |
66 | bool operator!=(const wxDataFormat& format) const | |
67 | { return m_format != format.m_format; } | |
68 | ||
69 | // explicit and implicit conversions to NativeFormat which is one of | |
70 | // standard data types (implicit conversion is useful for preserving the | |
71 | // compatibility with old code) | |
72 | NativeFormat GetFormatId() const { return m_format; } | |
73 | operator NativeFormat() const { return m_format; } | |
74 | ||
75 | // this only works with standard ids | |
76 | void SetId( wxDataFormatId type ); | |
3f480da3 | 77 | |
1dd989e1 RR |
78 | // this only works with standard ids |
79 | void SetId( NativeFormat format ); | |
3f480da3 | 80 | |
1dd989e1 RR |
81 | // string ids are used for custom types - this SetId() must be used for |
82 | // application-specific formats | |
3f480da3 VZ |
83 | wxString GetId() const; |
84 | void SetId( const wxChar *id ); | |
85 | ||
1dd989e1 RR |
86 | // implementation |
87 | wxDataFormatId GetType() const; | |
9726da4f | 88 | |
3f480da3 | 89 | private: |
1dd989e1 RR |
90 | wxDataFormatId m_type; |
91 | NativeFormat m_format; | |
e2acb9ae RR |
92 | |
93 | void PrepareFormats(); | |
1dd989e1 | 94 | void SetType( wxDataFormatId type ); |
8b53e5a2 RR |
95 | }; |
96 | ||
0d2a2b60 | 97 | //---------------------------------------------------------------------------- |
1dd989e1 | 98 | // wxDataObject |
0d2a2b60 RR |
99 | //---------------------------------------------------------------------------- |
100 | ||
101 | class wxDataObject : public wxObject | |
102 | { | |
0d2a2b60 | 103 | public: |
e2acb9ae | 104 | wxDataObject(); |
e2acb9ae | 105 | ~wxDataObject(); |
e2acb9ae | 106 | |
1dd989e1 RR |
107 | virtual wxDataFormat GetPreferredFormat() const = 0; |
108 | ||
109 | // get the number of formats we support: it is understood that if we | |
110 | // can accept data in some format, then we can render data in this | |
111 | // format as well, but the contrary is not necessarily true. For the | |
112 | // default value of the argument, all formats we support should be | |
113 | // returned, but if outputOnlyToo == FALSE, then we should only return | |
114 | // the formats which our SetData() understands | |
115 | virtual size_t GetFormatCount(bool outputOnlyToo = TRUE) const | |
116 | { return 1; } | |
117 | ||
118 | // return all formats in the provided array (of size GetFormatCount()) | |
119 | virtual void GetAllFormats(wxDataFormat *formats, | |
120 | bool outputOnlyToo = TRUE) const | |
121 | { formats[0] = GetPreferredFormat(); } | |
122 | ||
123 | // get the (total) size of data for the given format | |
124 | virtual size_t GetDataSize(const wxDataFormat& format) const = 0; | |
125 | ||
126 | // copy raw data (in the specified format) to provided pointer | |
127 | virtual bool GetDataHere(const wxDataFormat& format, void *buf) const = 0; | |
128 | ||
129 | // get data from the buffer (in the given format) | |
130 | virtual bool SetData(const wxDataFormat& format, const void *buf) = 0; | |
131 | ||
132 | // a simpler name which makes more sense for data objects supporting | |
133 | // only one format | |
134 | wxDataFormat GetFormat() const { return GetPreferredFormat(); } | |
3f480da3 | 135 | |
1dd989e1 RR |
136 | // old interface |
137 | // decide if we support this format (can be either standard or custom | |
138 | // format) -- now uses GetAllFormats() | |
139 | virtual bool IsSupportedFormat(const wxDataFormat& format) const; | |
3f480da3 | 140 | |
e2acb9ae RR |
141 | private: |
142 | DECLARE_DYNAMIC_CLASS( wxDataObject ) | |
0d2a2b60 RR |
143 | }; |
144 | ||
145 | //---------------------------------------------------------------------------- | |
8b53e5a2 | 146 | // wxTextDataObject is a specialization of wxDataObject for text data |
0d2a2b60 | 147 | //---------------------------------------------------------------------------- |
8b53e5a2 RR |
148 | |
149 | class wxTextDataObject : public wxDataObject | |
150 | { | |
8b53e5a2 | 151 | public: |
1dd989e1 | 152 | // ctors |
e2acb9ae | 153 | wxTextDataObject(); |
1dd989e1 RR |
154 | wxTextDataObject(const wxString& strText); |
155 | void Init(const wxString& strText) { m_strText = strText; } | |
156 | ||
157 | virtual wxDataFormat GetPreferredFormat() const | |
158 | { return wxDF_TEXT; } | |
159 | virtual bool IsSupportedFormat(const wxDataFormat& format) const | |
160 | { return format == wxDF_TEXT; } | |
161 | ||
162 | virtual size_t GetDataSize(const wxDataFormat& format) const; | |
163 | virtual bool GetDataHere(const wxDataFormat& format, void *buf) const; | |
164 | virtual bool SetData(const wxDataFormat& format, const void *buf); | |
165 | ||
166 | // additional helpers | |
167 | void SetText(const wxString& strText) { m_strText = strText; } | |
168 | wxString GetText() const { return m_strText; } | |
8b53e5a2 | 169 | |
1dd989e1 RR |
170 | private: |
171 | wxString m_strText; | |
172 | ||
e2acb9ae RR |
173 | private: |
174 | DECLARE_DYNAMIC_CLASS( wxTextDataObject ) | |
8b53e5a2 RR |
175 | }; |
176 | ||
0d2a2b60 | 177 | //---------------------------------------------------------------------------- |
8b53e5a2 | 178 | // wxFileDataObject is a specialization of wxDataObject for file names |
0d2a2b60 | 179 | //---------------------------------------------------------------------------- |
8b53e5a2 RR |
180 | |
181 | class wxFileDataObject : public wxDataObject | |
182 | { | |
8b53e5a2 | 183 | public: |
e2acb9ae | 184 | wxFileDataObject(); |
1dd989e1 | 185 | |
e2acb9ae | 186 | void AddFile( const wxString &file ); |
e2acb9ae | 187 | wxString GetFiles() const; |
1dd989e1 RR |
188 | |
189 | virtual wxDataFormat GetPreferredFormat() const | |
190 | { return wxDF_FILENAME; } | |
191 | virtual bool IsSupportedFormat(const wxDataFormat& format) const | |
192 | { return format == wxDF_FILENAME; } | |
193 | ||
194 | virtual size_t GetDataSize(const wxDataFormat& format) const; | |
195 | virtual bool GetDataHere(const wxDataFormat& format, void *buf) const; | |
196 | virtual bool SetData(const wxDataFormat& format, const void *buf); | |
3f480da3 | 197 | |
e2acb9ae | 198 | public: |
e2acb9ae RR |
199 | wxString m_files; |
200 | ||
201 | private: | |
202 | DECLARE_DYNAMIC_CLASS( wxFileDataObject ) | |
8b53e5a2 RR |
203 | }; |
204 | ||
0d2a2b60 | 205 | //---------------------------------------------------------------------------- |
8b53e5a2 | 206 | // wxBitmapDataObject is a specialization of wxDataObject for bitmaps |
0d2a2b60 | 207 | //---------------------------------------------------------------------------- |
8b53e5a2 RR |
208 | |
209 | class wxBitmapDataObject : public wxDataObject | |
210 | { | |
8b53e5a2 | 211 | public: |
1dd989e1 | 212 | // ctors |
e2acb9ae | 213 | wxBitmapDataObject(); |
1dd989e1 | 214 | wxBitmapDataObject(const wxBitmap& bitmap); |
e2acb9ae | 215 | |
1dd989e1 RR |
216 | // destr |
217 | ~wxBitmapDataObject(); | |
e2acb9ae | 218 | |
1dd989e1 RR |
219 | // set/get our bitmap |
220 | void SetBitmap(const wxBitmap& bitmap); | |
221 | const wxBitmap GetBitmap() const { return m_bitmap; } | |
222 | ||
223 | virtual wxDataFormat GetPreferredFormat() const | |
224 | { return wxDF_BITMAP; } | |
225 | virtual bool IsSupportedFormat(const wxDataFormat& format) const | |
226 | { return format == wxDF_BITMAP; } | |
227 | ||
228 | virtual size_t GetDataSize(const wxDataFormat& format) const; | |
229 | virtual bool GetDataHere(const wxDataFormat& format, void *buf) const; | |
230 | ||
231 | // sets PNG data | |
232 | virtual bool SetData(const wxDataFormat& format, const void *buf); | |
e2acb9ae | 233 | |
1dd989e1 RR |
234 | // sets PNG data |
235 | virtual void SetPngData(const void *buf, size_t size); | |
236 | ||
237 | void *GetData() | |
238 | { return m_pngData; } | |
239 | ||
e2acb9ae RR |
240 | private: |
241 | wxBitmap m_bitmap; | |
242 | size_t m_pngSize; | |
1dd989e1 | 243 | void *m_pngData; |
e2acb9ae RR |
244 | |
245 | void DoConvertToPng(); | |
246 | ||
247 | private: | |
248 | DECLARE_DYNAMIC_CLASS( wxBitmapDataObject ); | |
8b53e5a2 RR |
249 | }; |
250 | ||
3f480da3 | 251 | #endif |
8b53e5a2 RR |
252 | //__GTKDNDH__ |
253 |