]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk/dataobj.h
Removed LastError() from wxFilterStream
[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
f37615d7
RR
34//-------------------------------------------------------------------------
35// wxDataFormat (internal)
36//-------------------------------------------------------------------------
37
0d2a2b60
RR
38class wxDataFormat : public wxObject
39{
8b53e5a2 40public:
3f480da3
VZ
41 wxDataFormat();
42 wxDataFormat( wxDataFormatId type );
43 wxDataFormat( const wxString &id );
44 wxDataFormat( const wxChar *id );
9726da4f 45 wxDataFormat( const wxDataFormat &format );
3f480da3 46 wxDataFormat( const GdkAtom atom );
8b53e5a2 47
3f480da3
VZ
48 void SetType( wxDataFormatId type );
49 wxDataFormatId GetType() const;
50
51 /* the string Id identifies the format of clipboard or DnD data. a word
52 * processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
53 * to the clipboard - the latter with the Id "application/wxword", an
54 * image manipulation program would put a wxBitmapDataObject and a
55 * wxPrivateDataObject to the clipboard - the latter with "image/png". */
56
57 wxString GetId() const;
58 void SetId( const wxChar *id );
59
60 GdkAtom GetAtom();
61 void SetAtom(GdkAtom atom) { m_hasAtom = TRUE; m_atom = atom; }
62
9726da4f
VZ
63 // implicit conversion to wxDataFormatId
64 operator wxDataFormatId() const { return m_type; }
65
66 bool operator==(wxDataFormatId type) const { return m_type == type; }
67 bool operator!=(wxDataFormatId type) const { return m_type != type; }
68
3f480da3
VZ
69private:
70 wxDataFormatId m_type;
71 wxString m_id;
72 bool m_hasAtom;
73 GdkAtom m_atom;
e2acb9ae
RR
74
75 void PrepareFormats();
76
77private:
78 DECLARE_CLASS( wxDataFormat )
0d2a2b60 79};
8b53e5a2 80
0d2a2b60 81//-------------------------------------------------------------------------
f37615d7 82// wxDataBroker (internal)
0d2a2b60
RR
83//-------------------------------------------------------------------------
84
85class wxDataBroker : public wxObject
86{
0d2a2b60 87public:
e2acb9ae
RR
88 /* constructor */
89 wxDataBroker();
0d2a2b60 90
e2acb9ae
RR
91 /* add data object */
92 void Add( wxDataObject *dataObject, bool preferred = FALSE );
3f480da3
VZ
93
94private:
e2acb9ae 95 /* OLE implementation, the methods don't need to be overridden */
3f480da3 96
e2acb9ae
RR
97 /* get number of supported formats */
98 virtual size_t GetFormatCount() const;
3f480da3 99
e2acb9ae
RR
100 /* return nth supported format */
101 virtual wxDataFormat &GetNthFormat( size_t nth ) const;
3f480da3 102
e2acb9ae
RR
103 /* return preferrd/best supported format */
104 virtual wxDataFormatId GetPreferredFormat() const;
3f480da3 105
e2acb9ae
RR
106 /* search through m_dataObjects, return TRUE if found */
107 virtual bool IsSupportedFormat( wxDataFormat &format ) const;
3f480da3 108
e2acb9ae
RR
109 /* search through m_dataObjects and call child's GetSize() */
110 virtual size_t GetSize( wxDataFormat& format ) const;
3f480da3 111
e2acb9ae
RR
112 /* search through m_dataObjects and call child's WriteData(dest) */
113 virtual void WriteData( wxDataFormat& format, void *dest ) const;
0d2a2b60
RR
114
115public:
e2acb9ae
RR
116 /* implementation */
117 wxList m_dataObjects;
118 size_t m_preferred;
119
120private:
121 DECLARE_CLASS( wxDataBroker )
8b53e5a2
RR
122};
123
0d2a2b60
RR
124//----------------------------------------------------------------------------
125// wxDataObject to be placed in wxDataBroker
126//----------------------------------------------------------------------------
127
128class wxDataObject : public wxObject
129{
0d2a2b60 130public:
e2acb9ae
RR
131 /* constructor */
132 wxDataObject();
0d2a2b60 133
e2acb9ae
RR
134 /* destructor */
135 ~wxDataObject();
3f480da3 136
e2acb9ae
RR
137 /* write data to dest */
138 virtual void WriteData( void *dest ) const = 0;
3f480da3 139
e2acb9ae
RR
140 /* get size of data */
141 virtual size_t GetSize() const = 0;
3f480da3 142
e2acb9ae
RR
143public:
144 /* implementation */
145 wxDataFormat m_format;
146
147 wxDataFormat &GetFormat();
3f480da3 148
e2acb9ae
RR
149 wxDataFormatId GetFormatType() const;
150 wxString GetFormatId() const;
151 GdkAtom GetFormatAtom() const;
3f480da3 152
e2acb9ae
RR
153private:
154 DECLARE_DYNAMIC_CLASS( wxDataObject )
0d2a2b60
RR
155};
156
157//----------------------------------------------------------------------------
8b53e5a2 158// wxTextDataObject is a specialization of wxDataObject for text data
0d2a2b60 159//----------------------------------------------------------------------------
8b53e5a2
RR
160
161class wxTextDataObject : public wxDataObject
162{
8b53e5a2 163public:
e2acb9ae
RR
164 /* default constructor. call SetText() later or override
165 WriteData() and GetSize() for working on-demand */
166 wxTextDataObject();
8b53e5a2 167
e2acb9ae
RR
168 /* constructor */
169 wxTextDataObject( const wxString& data );
3f480da3 170
e2acb9ae
RR
171 /* set current text data */
172 void SetText( const wxString& data );
3f480da3 173
e2acb9ae
RR
174 /* get current text data */
175 wxString GetText() const;
3f480da3 176
e2acb9ae
RR
177 /* by default calls WriteString() with string set by constructor or
178 by SetText(). can be overridden for working on-demand */
179 virtual void WriteData( void *dest ) const;
8b53e5a2 180
e2acb9ae
RR
181 /* by default, returns length of string as set by constructor or
182 by SetText(). can be overridden for working on-demand */
183 virtual size_t GetSize() const;
3f480da3 184
e2acb9ae
RR
185 /* write string to dest */
186 void WriteString( const wxString &str, void *dest ) const;
3f480da3 187
e2acb9ae
RR
188public:
189 /* implementation */
190 wxString m_data;
8b53e5a2 191
e2acb9ae
RR
192private:
193 DECLARE_DYNAMIC_CLASS( wxTextDataObject )
8b53e5a2
RR
194};
195
0d2a2b60 196//----------------------------------------------------------------------------
8b53e5a2 197// wxFileDataObject is a specialization of wxDataObject for file names
0d2a2b60 198//----------------------------------------------------------------------------
8b53e5a2
RR
199
200class wxFileDataObject : public wxDataObject
201{
8b53e5a2 202public:
e2acb9ae
RR
203 /* default constructor */
204 wxFileDataObject();
8b53e5a2 205
e2acb9ae
RR
206 /* add file name to list */
207 void AddFile( const wxString &file );
3f480da3 208
e2acb9ae
RR
209 /* get all filename as one string. each file name is 0 terminated,
210 the list is double zero terminated */
211 wxString GetFiles() const;
3f480da3 212
e2acb9ae
RR
213 /* write list of filenames */
214 virtual void WriteData( void *dest ) const;
0d2a2b60 215
e2acb9ae
RR
216 /* return length of list of filenames */
217 virtual size_t GetSize() const;
3f480da3 218
e2acb9ae
RR
219public:
220 /* implementation */
221 wxString m_files;
222
223private:
224 DECLARE_DYNAMIC_CLASS( wxFileDataObject )
8b53e5a2
RR
225};
226
0d2a2b60 227//----------------------------------------------------------------------------
8b53e5a2 228// wxBitmapDataObject is a specialization of wxDataObject for bitmaps
0d2a2b60 229//----------------------------------------------------------------------------
8b53e5a2
RR
230
231class wxBitmapDataObject : public wxDataObject
232{
8b53e5a2 233public:
e2acb9ae
RR
234 /* see wxTextDataObject for explanation */
235 wxBitmapDataObject();
236 wxBitmapDataObject( const wxBitmap& bitmap );
237 ~wxBitmapDataObject();
238
239 void SetBitmap( const wxBitmap &bitmap );
240 wxBitmap GetBitmap() const;
241
242 virtual void WriteData( void *dest ) const;
243 virtual size_t GetSize() const;
244 void *GetData() const { return (void*)m_pngData; }
245
246 void WriteBitmap( const wxBitmap &bitmap, void *dest ) const;
247
248 void SetPngData( const char *pngData, size_t pngSize );
249
250private:
251 wxBitmap m_bitmap;
252 size_t m_pngSize;
253 char *m_pngData;
254
255 void DoConvertToPng();
256
257private:
258 DECLARE_DYNAMIC_CLASS( wxBitmapDataObject );
8b53e5a2
RR
259};
260
3f480da3 261#endif
8b53e5a2
RR
262 //__GTKDNDH__
263