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