]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk1/dataobj.h
Added
[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//-------------------------------------------------------------------------
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 );
107dcfab 73 wxDataFormat( const wxChar *id );
0d2a2b60
RR
74 wxDataFormat( wxDataFormat &format );
75 wxDataFormat( const GdkAtom atom );
cd5bf2a6
RR
76
77 void SetType( wxDataType type );
78 wxDataType GetType() const;
79
0d2a2b60 80 wxString GetId() const;
107dcfab 81 void SetId( const wxChar *id );
cd5bf2a6 82
0d2a2b60 83 GdkAtom GetAtom();
fc7840aa 84 void SetAtom(GdkAtom atom) { m_hasAtom = TRUE; m_atom = atom; }
0d2a2b60 85private:
8b53e5a2 86
cd5bf2a6
RR
87 wxDataType m_type;
88 wxString m_id;
89 bool m_hasAtom;
90 GdkAtom m_atom;
0d2a2b60 91};
8b53e5a2 92
0d2a2b60 93//-------------------------------------------------------------------------
f37615d7 94// wxDataBroker (internal)
0d2a2b60
RR
95//-------------------------------------------------------------------------
96
97class wxDataBroker : public wxObject
98{
99 DECLARE_CLASS( wxDataBroker )
100
101public:
102
103 /* constructor */
104 wxDataBroker();
8b53e5a2 105
0d2a2b60
RR
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 */
8b53e5a2 112
0d2a2b60
RR
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;
8b53e5a2
RR
137};
138
0d2a2b60
RR
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
cd5bf2a6
RR
163 wxDataFormat &GetFormat();
164
165 wxDataType GetFormatType() const;
166 wxString GetFormatId() const;
167 GdkAtom GetFormatAtom() const;
0d2a2b60 168
cd5bf2a6 169 wxDataFormat m_format;
0d2a2b60
RR
170};
171
172//----------------------------------------------------------------------------
8b53e5a2 173// wxTextDataObject is a specialization of wxDataObject for text data
0d2a2b60 174//----------------------------------------------------------------------------
8b53e5a2
RR
175
176class wxTextDataObject : public wxDataObject
177{
178 DECLARE_DYNAMIC_CLASS( wxTextDataObject )
179
180public:
181
0d2a2b60
RR
182 /* default constructor. call SetText() later or override
183 WriteData() and GetSize() for working on-demand */
184 wxTextDataObject();
8b53e5a2 185
0d2a2b60
RR
186 /* constructor */
187 wxTextDataObject( const wxString& data );
188
189 /* set current text data */
190 void SetText( const wxString& data );
8b53e5a2 191
0d2a2b60
RR
192 /* get current text data */
193 wxString GetText() const;
8b53e5a2 194
0d2a2b60
RR
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 */
8b53e5a2 207
0d2a2b60 208 wxString m_data;
8b53e5a2
RR
209};
210
0d2a2b60 211//----------------------------------------------------------------------------
8b53e5a2 212// wxFileDataObject is a specialization of wxDataObject for file names
0d2a2b60 213//----------------------------------------------------------------------------
8b53e5a2
RR
214
215class wxFileDataObject : public wxDataObject
216{
217 DECLARE_DYNAMIC_CLASS( wxFileDataObject )
218
219public:
220
0d2a2b60
RR
221 /* default constructor */
222 wxFileDataObject();
8b53e5a2 223
0d2a2b60
RR
224 /* add file name to list */
225 void AddFile( const wxString &file );
8b53e5a2 226
0d2a2b60
RR
227 /* get all filename as one string. each file name is 0 terminated,
228 the list is double zero terminated */
229 wxString GetFiles() const;
8b53e5a2 230
0d2a2b60
RR
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;
8b53e5a2 236
0d2a2b60
RR
237 /* implementation */
238
239 wxString m_files;
8b53e5a2
RR
240};
241
0d2a2b60 242//----------------------------------------------------------------------------
8b53e5a2 243// wxBitmapDataObject is a specialization of wxDataObject for bitmaps
0d2a2b60 244//----------------------------------------------------------------------------
8b53e5a2
RR
245
246class wxBitmapDataObject : public wxDataObject
247{
248 DECLARE_DYNAMIC_CLASS( wxBitmapDataObject )
249
250public:
251
0d2a2b60
RR
252 /* see wxTextDataObject for explanation */
253
254 wxBitmapDataObject();
255 wxBitmapDataObject( const wxBitmap& bitmap );
8b53e5a2 256
0d2a2b60
RR
257 void SetBitmap( const wxBitmap &bitmap );
258 wxBitmap GetBitmap() const;
b666df2c 259
0d2a2b60
RR
260 virtual void WriteData( void *dest ) const;
261 virtual size_t GetSize() const;
262
263 void WriteBitmap( const wxBitmap &bitmap, void *dest ) const;
8b53e5a2 264
0d2a2b60
RR
265 // implementation
266
8b53e5a2 267 wxBitmap m_bitmap;
0d2a2b60 268
8b53e5a2
RR
269};
270
0d2a2b60 271//----------------------------------------------------------------------------
8b53e5a2 272// wxPrivateDataObject is a specialization of wxDataObject for app specific data
0d2a2b60 273//----------------------------------------------------------------------------
8b53e5a2
RR
274
275class wxPrivateDataObject : public wxDataObject
276{
277 DECLARE_DYNAMIC_CLASS( wxPrivateDataObject )
278
279public:
280
0d2a2b60
RR
281 /* see wxTextDataObject for explanation of functions */
282
ab8884ac 283 wxPrivateDataObject();
ab8884ac 284 ~wxPrivateDataObject();
8b53e5a2 285
0d2a2b60
RR
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". */
8b53e5a2 291
0d2a2b60 292 void SetId( const wxString& id );
8b53e5a2 293
0d2a2b60
RR
294 /* get id */
295 wxString GetId() const;
8b53e5a2 296
0d2a2b60 297 /* set data. will make internal copy. */
8b53e5a2
RR
298 void SetData( const char *data, size_t size );
299
0d2a2b60
RR
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;
8b53e5a2 307
0d2a2b60
RR
308 // implementation
309
8b53e5a2
RR
310 size_t m_size;
311 char* m_data;
312 wxString m_id;
313};
314
315
316#endif
317 //__GTKDNDH__
318