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