]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk/dataobj.h
wxMimeTypesManager::IsOfType() added (and documented)
[wxWidgets.git] / include / wx / gtk / dataobj.h
CommitLineData
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
26class wxDataFormat;
27class wxDataBroker;
8b53e5a2
RR
28class wxDataObject;
29class wxTextDataObject;
30class wxBitmapDataObject;
31class wxPrivateDataObject;
32class wxFileDataObject;
33
34//-------------------------------------------------------------------------
f37615d7 35// wxDataType (internal)
8b53e5a2
RR
36//-------------------------------------------------------------------------
37
0d2a2b60 38enum wxDataType
8b53e5a2 39{
0d2a2b60
RR
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};
8b53e5a2 59
f37615d7
RR
60//-------------------------------------------------------------------------
61// wxDataFormat (internal)
62//-------------------------------------------------------------------------
63
0d2a2b60
RR
64class wxDataFormat : public wxObject
65{
66 DECLARE_CLASS( wxDataFormat )
67
8b53e5a2 68public:
0d2a2b60 69
cd5bf2a6 70 wxDataFormat();
0d2a2b60
RR
71 wxDataFormat( wxDataType type );
72 wxDataFormat( const wxString &id );
73 wxDataFormat( wxDataFormat &format );
74 wxDataFormat( const GdkAtom atom );
cd5bf2a6
RR
75
76 void SetType( wxDataType type );
77 wxDataType GetType() const;
78
0d2a2b60
RR
79 wxString GetId() const;
80 void SetId( const wxString &id );
cd5bf2a6 81
0d2a2b60
RR
82 GdkAtom GetAtom();
83
84private:
8b53e5a2 85
cd5bf2a6
RR
86 wxDataType m_type;
87 wxString m_id;
88 bool m_hasAtom;
89 GdkAtom m_atom;
0d2a2b60 90};
8b53e5a2 91
0d2a2b60 92//-------------------------------------------------------------------------
f37615d7 93// wxDataBroker (internal)
0d2a2b60
RR
94//-------------------------------------------------------------------------
95
96class wxDataBroker : public wxObject
97{
98 DECLARE_CLASS( wxDataBroker )
99
100public:
101
102 /* constructor */
103 wxDataBroker();
8b53e5a2 104
0d2a2b60
RR
105 /* add data object */
106 void Add( wxDataObject *dataObject, bool preferred = FALSE );
107
108private:
109
110 /* OLE implementation, the methods don't need to be overridden */
8b53e5a2 111
0d2a2b60
RR
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
132public:
133
134 wxList m_dataObjects;
135 size_t m_preferred;
8b53e5a2
RR
136};
137
0d2a2b60
RR
138//----------------------------------------------------------------------------
139// wxDataObject to be placed in wxDataBroker
140//----------------------------------------------------------------------------
141
142class wxDataObject : public wxObject
143{
144 DECLARE_DYNAMIC_CLASS( wxDataObject )
145
146public:
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
cd5bf2a6
RR
162 wxDataFormat &GetFormat();
163
164 wxDataType GetFormatType() const;
165 wxString GetFormatId() const;
166 GdkAtom GetFormatAtom() const;
0d2a2b60 167
cd5bf2a6 168 wxDataFormat m_format;
0d2a2b60
RR
169};
170
171//----------------------------------------------------------------------------
8b53e5a2 172// wxTextDataObject is a specialization of wxDataObject for text data
0d2a2b60 173//----------------------------------------------------------------------------
8b53e5a2
RR
174
175class wxTextDataObject : public wxDataObject
176{
177 DECLARE_DYNAMIC_CLASS( wxTextDataObject )
178
179public:
180
0d2a2b60
RR
181 /* default constructor. call SetText() later or override
182 WriteData() and GetSize() for working on-demand */
183 wxTextDataObject();
8b53e5a2 184
0d2a2b60
RR
185 /* constructor */
186 wxTextDataObject( const wxString& data );
187
188 /* set current text data */
189 void SetText( const wxString& data );
8b53e5a2 190
0d2a2b60
RR
191 /* get current text data */
192 wxString GetText() const;
8b53e5a2 193
0d2a2b60
RR
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 */
8b53e5a2 206
0d2a2b60 207 wxString m_data;
8b53e5a2
RR
208};
209
0d2a2b60 210//----------------------------------------------------------------------------
8b53e5a2 211// wxFileDataObject is a specialization of wxDataObject for file names
0d2a2b60 212//----------------------------------------------------------------------------
8b53e5a2
RR
213
214class wxFileDataObject : public wxDataObject
215{
216 DECLARE_DYNAMIC_CLASS( wxFileDataObject )
217
218public:
219
0d2a2b60
RR
220 /* default constructor */
221 wxFileDataObject();
8b53e5a2 222
0d2a2b60
RR
223 /* add file name to list */
224 void AddFile( const wxString &file );
8b53e5a2 225
0d2a2b60
RR
226 /* get all filename as one string. each file name is 0 terminated,
227 the list is double zero terminated */
228 wxString GetFiles() const;
8b53e5a2 229
0d2a2b60
RR
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;
8b53e5a2 235
0d2a2b60
RR
236 /* implementation */
237
238 wxString m_files;
8b53e5a2
RR
239};
240
0d2a2b60 241//----------------------------------------------------------------------------
8b53e5a2 242// wxBitmapDataObject is a specialization of wxDataObject for bitmaps
0d2a2b60 243//----------------------------------------------------------------------------
8b53e5a2
RR
244
245class wxBitmapDataObject : public wxDataObject
246{
247 DECLARE_DYNAMIC_CLASS( wxBitmapDataObject )
248
249public:
250
0d2a2b60
RR
251 /* see wxTextDataObject for explanation */
252
253 wxBitmapDataObject();
254 wxBitmapDataObject( const wxBitmap& bitmap );
8b53e5a2 255
0d2a2b60
RR
256 void SetBitmap( const wxBitmap &bitmap );
257 wxBitmap GetBitmap() const;
b666df2c 258
0d2a2b60
RR
259 virtual void WriteData( void *dest ) const;
260 virtual size_t GetSize() const;
261
262 void WriteBitmap( const wxBitmap &bitmap, void *dest ) const;
8b53e5a2 263
0d2a2b60
RR
264 // implementation
265
8b53e5a2 266 wxBitmap m_bitmap;
0d2a2b60 267
8b53e5a2
RR
268};
269
0d2a2b60 270//----------------------------------------------------------------------------
8b53e5a2 271// wxPrivateDataObject is a specialization of wxDataObject for app specific data
0d2a2b60 272//----------------------------------------------------------------------------
8b53e5a2
RR
273
274class wxPrivateDataObject : public wxDataObject
275{
276 DECLARE_DYNAMIC_CLASS( wxPrivateDataObject )
277
278public:
279
0d2a2b60
RR
280 /* see wxTextDataObject for explanation of functions */
281
ab8884ac 282 wxPrivateDataObject();
ab8884ac 283 ~wxPrivateDataObject();
8b53e5a2 284
0d2a2b60
RR
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". */
8b53e5a2 290
0d2a2b60 291 void SetId( const wxString& id );
8b53e5a2 292
0d2a2b60
RR
293 /* get id */
294 wxString GetId() const;
8b53e5a2 295
0d2a2b60 296 /* set data. will make internal copy. */
8b53e5a2
RR
297 void SetData( const char *data, size_t size );
298
0d2a2b60
RR
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;
8b53e5a2 306
0d2a2b60
RR
307 // implementation
308
8b53e5a2
RR
309 size_t m_size;
310 char* m_data;
311 wxString m_id;
312};
313
314
315#endif
316 //__GTKDNDH__
317