]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/dataobj.h
Further DnD changes. Untested.
[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
36 //-------------------------------------------------------------------------
37
38 class wxDataFormat
39 {
40 public:
41 // the clipboard formats under GDK are GdkAtoms
42 typedef GdkAtom NativeFormat;
43
44 wxDataFormat();
45 wxDataFormat( wxDataFormatId type );
46 wxDataFormat( const wxString &id );
47 wxDataFormat( const wxChar *id );
48 wxDataFormat( NativeFormat format );
49
50 wxDataFormat& operator=(NativeFormat format)
51 { SetId(format); return *this; }
52 wxDataFormat& operator=(const wxDataFormat& format)
53 { SetId(format); return *this; }
54
55 // comparison (must have both versions)
56 bool operator==(wxDataFormatId type) const
57 { return m_type == (wxDataFormatId)type; }
58 bool operator!=(wxDataFormatId type) const
59 { return m_type != (wxDataFormatId)type; }
60 bool operator==(NativeFormat format) const
61 { return m_format == (NativeFormat)format; }
62 bool operator!=(NativeFormat format) const
63 { return m_format != (NativeFormat)format; }
64 bool operator==(const wxDataFormat& format) const
65 { return m_format == format.m_format; }
66 bool operator!=(const wxDataFormat& format) const
67 { return m_format != format.m_format; }
68
69 // explicit and implicit conversions to NativeFormat which is one of
70 // standard data types (implicit conversion is useful for preserving the
71 // compatibility with old code)
72 NativeFormat GetFormatId() const { return m_format; }
73 operator NativeFormat() const { return m_format; }
74
75 // this only works with standard ids
76 void SetId( wxDataFormatId type );
77
78 // this only works with standard ids
79 void SetId( NativeFormat format );
80
81 // string ids are used for custom types - this SetId() must be used for
82 // application-specific formats
83 wxString GetId() const;
84 void SetId( const wxChar *id );
85
86 // implementation
87 wxDataFormatId GetType() const;
88
89 private:
90 wxDataFormatId m_type;
91 NativeFormat m_format;
92
93 void PrepareFormats();
94 void SetType( wxDataFormatId type );
95 };
96
97 //----------------------------------------------------------------------------
98 // wxDataObject
99 //----------------------------------------------------------------------------
100
101 class wxDataObject : public wxObject
102 {
103 public:
104 wxDataObject();
105 ~wxDataObject();
106
107 virtual wxDataFormat GetPreferredFormat() const = 0;
108
109 // get the number of formats we support: it is understood that if we
110 // can accept data in some format, then we can render data in this
111 // format as well, but the contrary is not necessarily true. For the
112 // default value of the argument, all formats we support should be
113 // returned, but if outputOnlyToo == FALSE, then we should only return
114 // the formats which our SetData() understands
115 virtual size_t GetFormatCount(bool outputOnlyToo = TRUE) const
116 { return 1; }
117
118 // return all formats in the provided array (of size GetFormatCount())
119 virtual void GetAllFormats(wxDataFormat *formats,
120 bool outputOnlyToo = TRUE) const
121 { formats[0] = GetPreferredFormat(); }
122
123 // get the (total) size of data for the given format
124 virtual size_t GetDataSize(const wxDataFormat& format) const = 0;
125
126 // copy raw data (in the specified format) to provided pointer
127 virtual bool GetDataHere(const wxDataFormat& format, void *buf) const = 0;
128
129 // get data from the buffer (in the given format)
130 virtual bool SetData(const wxDataFormat& format, const void *buf) = 0;
131
132 // a simpler name which makes more sense for data objects supporting
133 // only one format
134 wxDataFormat GetFormat() const { return GetPreferredFormat(); }
135
136 // old interface
137 // decide if we support this format (can be either standard or custom
138 // format) -- now uses GetAllFormats()
139 virtual bool IsSupportedFormat(const wxDataFormat& format) const;
140
141 private:
142 DECLARE_DYNAMIC_CLASS( wxDataObject )
143 };
144
145 //----------------------------------------------------------------------------
146 // wxTextDataObject is a specialization of wxDataObject for text data
147 //----------------------------------------------------------------------------
148
149 class wxTextDataObject : public wxDataObject
150 {
151 public:
152 // ctors
153 wxTextDataObject();
154 wxTextDataObject(const wxString& strText);
155 void Init(const wxString& strText) { m_strText = strText; }
156
157 virtual wxDataFormat GetPreferredFormat() const
158 { return wxDF_TEXT; }
159 virtual bool IsSupportedFormat(const wxDataFormat& format) const
160 { return format == wxDF_TEXT; }
161
162 virtual size_t GetDataSize(const wxDataFormat& format) const;
163 virtual bool GetDataHere(const wxDataFormat& format, void *buf) const;
164 virtual bool SetData(const wxDataFormat& format, const void *buf);
165
166 // additional helpers
167 void SetText(const wxString& strText) { m_strText = strText; }
168 wxString GetText() const { return m_strText; }
169
170 private:
171 wxString m_strText;
172
173 private:
174 DECLARE_DYNAMIC_CLASS( wxTextDataObject )
175 };
176
177 //----------------------------------------------------------------------------
178 // wxFileDataObject is a specialization of wxDataObject for file names
179 //----------------------------------------------------------------------------
180
181 class wxFileDataObject : public wxDataObject
182 {
183 public:
184 wxFileDataObject();
185
186 void AddFile( const wxString &file );
187 void SetFiles( const wxString &files )
188 { m_files = files; }
189 wxString GetFiles() const;
190
191 virtual wxDataFormat GetPreferredFormat() const
192 { return wxDF_FILENAME; }
193 virtual bool IsSupportedFormat(const wxDataFormat& format) const
194 { return format == wxDF_FILENAME; }
195
196 virtual size_t GetDataSize(const wxDataFormat& format) const;
197 virtual bool GetDataHere(const wxDataFormat& format, void *buf) const;
198 virtual bool SetData(const wxDataFormat& format, const void *buf);
199
200 public:
201 wxString m_files;
202
203 private:
204 DECLARE_DYNAMIC_CLASS( wxFileDataObject )
205 };
206
207 //----------------------------------------------------------------------------
208 // wxBitmapDataObject is a specialization of wxDataObject for bitmaps
209 //----------------------------------------------------------------------------
210
211 class wxBitmapDataObject : public wxDataObject
212 {
213 public:
214 // ctors
215 wxBitmapDataObject();
216 wxBitmapDataObject(const wxBitmap& bitmap);
217
218 // destr
219 ~wxBitmapDataObject();
220
221 // set/get our bitmap
222 void SetBitmap(const wxBitmap& bitmap);
223 const wxBitmap GetBitmap() const { return m_bitmap; }
224
225 virtual wxDataFormat GetPreferredFormat() const
226 { return wxDF_BITMAP; }
227 virtual bool IsSupportedFormat(const wxDataFormat& format) const
228 { return format == wxDF_BITMAP; }
229
230 virtual size_t GetDataSize(const wxDataFormat& format) const;
231 virtual bool GetDataHere(const wxDataFormat& format, void *buf) const;
232
233 // sets PNG data
234 virtual bool SetData(const wxDataFormat& format, const void *buf);
235
236 // sets PNG data
237 virtual void SetPngData(const void *buf, size_t size);
238
239 void *GetData()
240 { return m_pngData; }
241
242 private:
243 wxBitmap m_bitmap;
244 size_t m_pngSize;
245 void *m_pngData;
246
247 void DoConvertToPng();
248
249 private:
250 DECLARE_DYNAMIC_CLASS( wxBitmapDataObject );
251 };
252
253 #endif
254 //__GTKDNDH__
255