]>
Commit | Line | Data |
---|---|---|
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 | ||
26 | class wxDataFormat; | |
27 | class wxDataBroker; | |
28 | class wxDataObject; | |
29 | class wxTextDataObject; | |
30 | class wxBitmapDataObject; | |
31 | class wxPrivateDataObject; | |
32 | class wxFileDataObject; | |
33 | ||
34 | //------------------------------------------------------------------------- | |
35 | // wxDataFormat | |
36 | //------------------------------------------------------------------------- | |
37 | ||
38 | enum wxDataType | |
39 | { | |
40 | wxDF_INVALID = 0, | |
41 | wxDF_TEXT = 1, /* CF_TEXT */ | |
42 | wxDF_BITMAP = 2, /* CF_BITMAP */ | |
43 | wxDF_METAFILE = 3, /* CF_METAFILEPICT */ | |
44 | wxDF_SYLK = 4, | |
45 | wxDF_DIF = 5, | |
46 | wxDF_TIFF = 6, | |
47 | wxDF_OEMTEXT = 7, /* CF_OEMTEXT */ | |
48 | wxDF_DIB = 8, /* CF_DIB */ | |
49 | wxDF_PALETTE = 9, | |
50 | wxDF_PENDATA = 10, | |
51 | wxDF_RIFF = 11, | |
52 | wxDF_WAVE = 12, | |
53 | wxDF_UNICODETEXT = 13, | |
54 | wxDF_ENHMETAFILE = 14, | |
55 | wxDF_FILENAME = 15, /* CF_HDROP */ | |
56 | wxDF_LOCALE = 16, | |
57 | wxDF_PRIVATE = 20 | |
58 | }; | |
59 | ||
60 | class wxDataFormat : public wxObject | |
61 | { | |
62 | DECLARE_CLASS( wxDataFormat ) | |
63 | ||
64 | public: | |
65 | ||
66 | wxDataFormat(); | |
67 | wxDataFormat( wxDataType type ); | |
68 | wxDataFormat( const wxString &id ); | |
69 | wxDataFormat( wxDataFormat &format ); | |
70 | wxDataFormat( const GdkAtom atom ); | |
71 | ||
72 | void SetType( wxDataType type ); | |
73 | wxDataType GetType() const; | |
74 | ||
75 | wxString GetId() const; | |
76 | void SetId( const wxString &id ); | |
77 | ||
78 | GdkAtom GetAtom(); | |
79 | ||
80 | private: | |
81 | ||
82 | wxDataType m_type; | |
83 | wxString m_id; | |
84 | bool m_hasAtom; | |
85 | GdkAtom m_atom; | |
86 | }; | |
87 | ||
88 | //------------------------------------------------------------------------- | |
89 | // wxDataBroker handles data and ormat negotiation for clipboard and DnD | |
90 | //------------------------------------------------------------------------- | |
91 | ||
92 | class wxDataBroker : public wxObject | |
93 | { | |
94 | DECLARE_CLASS( wxDataBroker ) | |
95 | ||
96 | public: | |
97 | ||
98 | /* constructor */ | |
99 | wxDataBroker(); | |
100 | ||
101 | /* add data object */ | |
102 | void Add( wxDataObject *dataObject, bool preferred = FALSE ); | |
103 | ||
104 | private: | |
105 | ||
106 | /* OLE implementation, the methods don't need to be overridden */ | |
107 | ||
108 | /* get number of supported formats */ | |
109 | virtual size_t GetFormatCount() const; | |
110 | ||
111 | /* return nth supported format */ | |
112 | virtual wxDataFormat &GetNthFormat( size_t nth ) const; | |
113 | ||
114 | /* return preferrd/best supported format */ | |
115 | virtual wxDataFormat &GetPreferredFormat() const; | |
116 | ||
117 | /* search through m_dataObjects, return TRUE if found */ | |
118 | virtual bool IsSupportedFormat( wxDataFormat &format ) const; | |
119 | ||
120 | /* search through m_dataObjects and call child's GetSize() */ | |
121 | virtual size_t GetSize( wxDataFormat& format ) const; | |
122 | ||
123 | /* search through m_dataObjects and call child's WriteData(dest) */ | |
124 | virtual void WriteData( wxDataFormat& format, void *dest ) const; | |
125 | ||
126 | /* implementation */ | |
127 | ||
128 | public: | |
129 | ||
130 | wxList m_dataObjects; | |
131 | size_t m_preferred; | |
132 | }; | |
133 | ||
134 | //---------------------------------------------------------------------------- | |
135 | // wxDataObject to be placed in wxDataBroker | |
136 | //---------------------------------------------------------------------------- | |
137 | ||
138 | class wxDataObject : public wxObject | |
139 | { | |
140 | DECLARE_DYNAMIC_CLASS( wxDataObject ) | |
141 | ||
142 | public: | |
143 | ||
144 | /* constructor */ | |
145 | wxDataObject(); | |
146 | ||
147 | /* destructor */ | |
148 | ~wxDataObject(); | |
149 | ||
150 | /* write data to dest */ | |
151 | virtual void WriteData( void *dest ) const = 0; | |
152 | ||
153 | /* get size of data */ | |
154 | virtual size_t GetSize() const = 0; | |
155 | ||
156 | /* implementation */ | |
157 | ||
158 | wxDataFormat &GetFormat(); | |
159 | ||
160 | wxDataType GetFormatType() const; | |
161 | wxString GetFormatId() const; | |
162 | GdkAtom GetFormatAtom() const; | |
163 | ||
164 | wxDataFormat m_format; | |
165 | }; | |
166 | ||
167 | //---------------------------------------------------------------------------- | |
168 | // wxTextDataObject is a specialization of wxDataObject for text data | |
169 | //---------------------------------------------------------------------------- | |
170 | ||
171 | class wxTextDataObject : public wxDataObject | |
172 | { | |
173 | DECLARE_DYNAMIC_CLASS( wxTextDataObject ) | |
174 | ||
175 | public: | |
176 | ||
177 | /* default constructor. call SetText() later or override | |
178 | WriteData() and GetSize() for working on-demand */ | |
179 | wxTextDataObject(); | |
180 | ||
181 | /* constructor */ | |
182 | wxTextDataObject( const wxString& data ); | |
183 | ||
184 | /* set current text data */ | |
185 | void SetText( const wxString& data ); | |
186 | ||
187 | /* get current text data */ | |
188 | wxString GetText() const; | |
189 | ||
190 | /* by default calls WriteString() with string set by constructor or | |
191 | by SetText(). can be overridden for working on-demand */ | |
192 | virtual void WriteData( void *dest ) const; | |
193 | ||
194 | /* by default, returns length of string as set by constructor or | |
195 | by SetText(). can be overridden for working on-demand */ | |
196 | virtual size_t GetSize() const; | |
197 | ||
198 | /* write string to dest */ | |
199 | void WriteString( const wxString &str, void *dest ) const; | |
200 | ||
201 | /* implementation */ | |
202 | ||
203 | wxString m_data; | |
204 | }; | |
205 | ||
206 | //---------------------------------------------------------------------------- | |
207 | // wxFileDataObject is a specialization of wxDataObject for file names | |
208 | //---------------------------------------------------------------------------- | |
209 | ||
210 | class wxFileDataObject : public wxDataObject | |
211 | { | |
212 | DECLARE_DYNAMIC_CLASS( wxFileDataObject ) | |
213 | ||
214 | public: | |
215 | ||
216 | /* default constructor */ | |
217 | wxFileDataObject(); | |
218 | ||
219 | /* add file name to list */ | |
220 | void AddFile( const wxString &file ); | |
221 | ||
222 | /* get all filename as one string. each file name is 0 terminated, | |
223 | the list is double zero terminated */ | |
224 | wxString GetFiles() const; | |
225 | ||
226 | /* write list of filenames */ | |
227 | virtual void WriteData( void *dest ) const; | |
228 | ||
229 | /* return length of list of filenames */ | |
230 | virtual size_t GetSize() const; | |
231 | ||
232 | /* implementation */ | |
233 | ||
234 | wxString m_files; | |
235 | }; | |
236 | ||
237 | //---------------------------------------------------------------------------- | |
238 | // wxBitmapDataObject is a specialization of wxDataObject for bitmaps | |
239 | //---------------------------------------------------------------------------- | |
240 | ||
241 | class wxBitmapDataObject : public wxDataObject | |
242 | { | |
243 | DECLARE_DYNAMIC_CLASS( wxBitmapDataObject ) | |
244 | ||
245 | public: | |
246 | ||
247 | /* see wxTextDataObject for explanation */ | |
248 | ||
249 | wxBitmapDataObject(); | |
250 | wxBitmapDataObject( const wxBitmap& bitmap ); | |
251 | ||
252 | void SetBitmap( const wxBitmap &bitmap ); | |
253 | wxBitmap GetBitmap() const; | |
254 | ||
255 | virtual void WriteData( void *dest ) const; | |
256 | virtual size_t GetSize() const; | |
257 | ||
258 | void WriteBitmap( const wxBitmap &bitmap, void *dest ) const; | |
259 | ||
260 | // implementation | |
261 | ||
262 | wxBitmap m_bitmap; | |
263 | ||
264 | }; | |
265 | ||
266 | //---------------------------------------------------------------------------- | |
267 | // wxPrivateDataObject is a specialization of wxDataObject for app specific data | |
268 | //---------------------------------------------------------------------------- | |
269 | ||
270 | class wxPrivateDataObject : public wxDataObject | |
271 | { | |
272 | DECLARE_DYNAMIC_CLASS( wxPrivateDataObject ) | |
273 | ||
274 | public: | |
275 | ||
276 | /* see wxTextDataObject for explanation of functions */ | |
277 | ||
278 | wxPrivateDataObject(); | |
279 | ~wxPrivateDataObject(); | |
280 | ||
281 | /* the string Id identifies the format of clipboard or DnD data. a word | |
282 | * processor would e.g. add a wxTextDataObject and a wxPrivateDataObject | |
283 | * to the clipboard - the latter with the Id "application/wxword", an | |
284 | * image manipulation program would put a wxBitmapDataObject and a | |
285 | * wxPrivateDataObject to the clipboard - the latter with "image/png". */ | |
286 | ||
287 | void SetId( const wxString& id ); | |
288 | ||
289 | /* get id */ | |
290 | wxString GetId() const; | |
291 | ||
292 | /* set data. will make internal copy. */ | |
293 | void SetData( const char *data, size_t size ); | |
294 | ||
295 | /* returns pointer to data */ | |
296 | char* GetData() const; | |
297 | ||
298 | virtual void WriteData( void *dest ) const; | |
299 | virtual size_t GetSize() const; | |
300 | ||
301 | void WriteData( const char *data, void *dest ) const; | |
302 | ||
303 | // implementation | |
304 | ||
305 | size_t m_size; | |
306 | char* m_data; | |
307 | wxString m_id; | |
308 | }; | |
309 | ||
310 | ||
311 | #endif | |
312 | //__GTKDNDH__ | |
313 |