]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk1/dataobj.h
Added Joel's wxchar.h for future Unicode adventures
[wxWidgets.git] / include / wx / gtk1 / 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//-------------------------------------------------------------------------
0d2a2b60 35// wxDataFormat
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
0d2a2b60
RR
60class wxDataFormat : public wxObject
61{
62 DECLARE_CLASS( wxDataFormat )
63
8b53e5a2 64public:
0d2a2b60 65
cd5bf2a6 66 wxDataFormat();
0d2a2b60
RR
67 wxDataFormat( wxDataType type );
68 wxDataFormat( const wxString &id );
69 wxDataFormat( wxDataFormat &format );
70 wxDataFormat( const GdkAtom atom );
cd5bf2a6
RR
71
72 void SetType( wxDataType type );
73 wxDataType GetType() const;
74
0d2a2b60
RR
75 wxString GetId() const;
76 void SetId( const wxString &id );
cd5bf2a6 77
0d2a2b60
RR
78 GdkAtom GetAtom();
79
80private:
8b53e5a2 81
cd5bf2a6
RR
82 wxDataType m_type;
83 wxString m_id;
84 bool m_hasAtom;
85 GdkAtom m_atom;
0d2a2b60 86};
8b53e5a2 87
0d2a2b60
RR
88//-------------------------------------------------------------------------
89// wxDataBroker handles data and ormat negotiation for clipboard and DnD
90//-------------------------------------------------------------------------
91
92class wxDataBroker : public wxObject
93{
94 DECLARE_CLASS( wxDataBroker )
95
96public:
97
98 /* constructor */
99 wxDataBroker();
8b53e5a2 100
0d2a2b60
RR
101 /* add data object */
102 void Add( wxDataObject *dataObject, bool preferred = FALSE );
103
104private:
105
106 /* OLE implementation, the methods don't need to be overridden */
8b53e5a2 107
0d2a2b60
RR
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
128public:
129
130 wxList m_dataObjects;
131 size_t m_preferred;
8b53e5a2
RR
132};
133
0d2a2b60
RR
134//----------------------------------------------------------------------------
135// wxDataObject to be placed in wxDataBroker
136//----------------------------------------------------------------------------
137
138class wxDataObject : public wxObject
139{
140 DECLARE_DYNAMIC_CLASS( wxDataObject )
141
142public:
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
cd5bf2a6
RR
158 wxDataFormat &GetFormat();
159
160 wxDataType GetFormatType() const;
161 wxString GetFormatId() const;
162 GdkAtom GetFormatAtom() const;
0d2a2b60 163
cd5bf2a6 164 wxDataFormat m_format;
0d2a2b60
RR
165};
166
167//----------------------------------------------------------------------------
8b53e5a2 168// wxTextDataObject is a specialization of wxDataObject for text data
0d2a2b60 169//----------------------------------------------------------------------------
8b53e5a2
RR
170
171class wxTextDataObject : public wxDataObject
172{
173 DECLARE_DYNAMIC_CLASS( wxTextDataObject )
174
175public:
176
0d2a2b60
RR
177 /* default constructor. call SetText() later or override
178 WriteData() and GetSize() for working on-demand */
179 wxTextDataObject();
8b53e5a2 180
0d2a2b60
RR
181 /* constructor */
182 wxTextDataObject( const wxString& data );
183
184 /* set current text data */
185 void SetText( const wxString& data );
8b53e5a2 186
0d2a2b60
RR
187 /* get current text data */
188 wxString GetText() const;
8b53e5a2 189
0d2a2b60
RR
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 */
8b53e5a2 202
0d2a2b60 203 wxString m_data;
8b53e5a2
RR
204};
205
0d2a2b60 206//----------------------------------------------------------------------------
8b53e5a2 207// wxFileDataObject is a specialization of wxDataObject for file names
0d2a2b60 208//----------------------------------------------------------------------------
8b53e5a2
RR
209
210class wxFileDataObject : public wxDataObject
211{
212 DECLARE_DYNAMIC_CLASS( wxFileDataObject )
213
214public:
215
0d2a2b60
RR
216 /* default constructor */
217 wxFileDataObject();
8b53e5a2 218
0d2a2b60
RR
219 /* add file name to list */
220 void AddFile( const wxString &file );
8b53e5a2 221
0d2a2b60
RR
222 /* get all filename as one string. each file name is 0 terminated,
223 the list is double zero terminated */
224 wxString GetFiles() const;
8b53e5a2 225
0d2a2b60
RR
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;
8b53e5a2 231
0d2a2b60
RR
232 /* implementation */
233
234 wxString m_files;
8b53e5a2
RR
235};
236
0d2a2b60 237//----------------------------------------------------------------------------
8b53e5a2 238// wxBitmapDataObject is a specialization of wxDataObject for bitmaps
0d2a2b60 239//----------------------------------------------------------------------------
8b53e5a2
RR
240
241class wxBitmapDataObject : public wxDataObject
242{
243 DECLARE_DYNAMIC_CLASS( wxBitmapDataObject )
244
245public:
246
0d2a2b60
RR
247 /* see wxTextDataObject for explanation */
248
249 wxBitmapDataObject();
250 wxBitmapDataObject( const wxBitmap& bitmap );
8b53e5a2 251
0d2a2b60
RR
252 void SetBitmap( const wxBitmap &bitmap );
253 wxBitmap GetBitmap() const;
b666df2c 254
0d2a2b60
RR
255 virtual void WriteData( void *dest ) const;
256 virtual size_t GetSize() const;
257
258 void WriteBitmap( const wxBitmap &bitmap, void *dest ) const;
8b53e5a2 259
0d2a2b60
RR
260 // implementation
261
8b53e5a2 262 wxBitmap m_bitmap;
0d2a2b60 263
8b53e5a2
RR
264};
265
0d2a2b60 266//----------------------------------------------------------------------------
8b53e5a2 267// wxPrivateDataObject is a specialization of wxDataObject for app specific data
0d2a2b60 268//----------------------------------------------------------------------------
8b53e5a2
RR
269
270class wxPrivateDataObject : public wxDataObject
271{
272 DECLARE_DYNAMIC_CLASS( wxPrivateDataObject )
273
274public:
275
0d2a2b60
RR
276 /* see wxTextDataObject for explanation of functions */
277
ab8884ac 278 wxPrivateDataObject();
ab8884ac 279 ~wxPrivateDataObject();
8b53e5a2 280
0d2a2b60
RR
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". */
8b53e5a2 286
0d2a2b60 287 void SetId( const wxString& id );
8b53e5a2 288
0d2a2b60
RR
289 /* get id */
290 wxString GetId() const;
8b53e5a2 291
0d2a2b60 292 /* set data. will make internal copy. */
8b53e5a2
RR
293 void SetData( const char *data, size_t size );
294
0d2a2b60
RR
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;
8b53e5a2 302
0d2a2b60
RR
303 // implementation
304
8b53e5a2
RR
305 size_t m_size;
306 char* m_data;
307 wxString m_id;
308};
309
310
311#endif
312 //__GTKDNDH__
313