]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/dataobj.h
HTML_xxxx constants changed to wxHTML_xxxx (with backward compatibility through WXWIN...
[wxWidgets.git] / include / wx / gtk / dataobj.h
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
26 class wxDataFormat;
27 class wxDataBroker;
28 class wxDataObject;
29 class wxTextDataObject;
30 class wxBitmapDataObject;
31 class wxPrivateDataObject;
32 class wxFileDataObject;
33
34 //-------------------------------------------------------------------------
35 // wxDataFormat (internal)
36 //-------------------------------------------------------------------------
37
38 class wxDataFormat : public wxObject
39 {
40 public:
41 wxDataFormat();
42 wxDataFormat( wxDataFormatId type );
43 wxDataFormat( const wxString &id );
44 wxDataFormat( const wxChar *id );
45 wxDataFormat( const wxDataFormat &format );
46 wxDataFormat( const GdkAtom atom );
47
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
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
69 private:
70 wxDataFormatId m_type;
71 wxString m_id;
72 bool m_hasAtom;
73 GdkAtom m_atom;
74
75 void PrepareFormats();
76
77 private:
78 DECLARE_CLASS( wxDataFormat )
79 };
80
81 //-------------------------------------------------------------------------
82 // wxDataBroker (internal)
83 //-------------------------------------------------------------------------
84
85 class wxDataBroker : public wxObject
86 {
87 public:
88 /* constructor */
89 wxDataBroker();
90
91 /* add data object */
92 void Add( wxDataObject *dataObject, bool preferred = FALSE );
93
94 private:
95 /* OLE implementation, the methods don't need to be overridden */
96
97 /* get number of supported formats */
98 virtual size_t GetFormatCount() const;
99
100 /* return nth supported format */
101 virtual wxDataFormat &GetNthFormat( size_t nth ) const;
102
103 /* return preferrd/best supported format */
104 virtual wxDataFormatId GetPreferredFormat() const;
105
106 /* search through m_dataObjects, return TRUE if found */
107 virtual bool IsSupportedFormat( wxDataFormat &format ) const;
108
109 /* search through m_dataObjects and call child's GetSize() */
110 virtual size_t GetSize( wxDataFormat& format ) const;
111
112 /* search through m_dataObjects and call child's WriteData(dest) */
113 virtual void WriteData( wxDataFormat& format, void *dest ) const;
114
115 public:
116 /* implementation */
117 wxList m_dataObjects;
118 size_t m_preferred;
119
120 private:
121 DECLARE_CLASS( wxDataBroker )
122 };
123
124 //----------------------------------------------------------------------------
125 // wxDataObject to be placed in wxDataBroker
126 //----------------------------------------------------------------------------
127
128 class wxDataObject : public wxObject
129 {
130 public:
131 /* constructor */
132 wxDataObject();
133
134 /* destructor */
135 ~wxDataObject();
136
137 /* write data to dest */
138 virtual void WriteData( void *dest ) const = 0;
139
140 /* get size of data */
141 virtual size_t GetSize() const = 0;
142
143 public:
144 /* implementation */
145 wxDataFormat m_format;
146
147 wxDataFormat &GetFormat();
148
149 wxDataFormatId GetFormatType() const;
150 wxString GetFormatId() const;
151 GdkAtom GetFormatAtom() const;
152
153 private:
154 DECLARE_DYNAMIC_CLASS( wxDataObject )
155 };
156
157 //----------------------------------------------------------------------------
158 // wxTextDataObject is a specialization of wxDataObject for text data
159 //----------------------------------------------------------------------------
160
161 class wxTextDataObject : public wxDataObject
162 {
163 public:
164 /* default constructor. call SetText() later or override
165 WriteData() and GetSize() for working on-demand */
166 wxTextDataObject();
167
168 /* constructor */
169 wxTextDataObject( const wxString& data );
170
171 /* set current text data */
172 void SetText( const wxString& data );
173
174 /* get current text data */
175 wxString GetText() const;
176
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;
180
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;
184
185 /* write string to dest */
186 void WriteString( const wxString &str, void *dest ) const;
187
188 public:
189 /* implementation */
190 wxString m_data;
191
192 private:
193 DECLARE_DYNAMIC_CLASS( wxTextDataObject )
194 };
195
196 //----------------------------------------------------------------------------
197 // wxFileDataObject is a specialization of wxDataObject for file names
198 //----------------------------------------------------------------------------
199
200 class wxFileDataObject : public wxDataObject
201 {
202 public:
203 /* default constructor */
204 wxFileDataObject();
205
206 /* add file name to list */
207 void AddFile( const wxString &file );
208
209 /* get all filename as one string. each file name is 0 terminated,
210 the list is double zero terminated */
211 wxString GetFiles() const;
212
213 /* write list of filenames */
214 virtual void WriteData( void *dest ) const;
215
216 /* return length of list of filenames */
217 virtual size_t GetSize() const;
218
219 public:
220 /* implementation */
221 wxString m_files;
222
223 private:
224 DECLARE_DYNAMIC_CLASS( wxFileDataObject )
225 };
226
227 //----------------------------------------------------------------------------
228 // wxBitmapDataObject is a specialization of wxDataObject for bitmaps
229 //----------------------------------------------------------------------------
230
231 class wxBitmapDataObject : public wxDataObject
232 {
233 public:
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
250 private:
251 wxBitmap m_bitmap;
252 size_t m_pngSize;
253 char *m_pngData;
254
255 void DoConvertToPng();
256
257 private:
258 DECLARE_DYNAMIC_CLASS( wxBitmapDataObject );
259 };
260
261 #endif
262 //__GTKDNDH__
263