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