]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk1/dataobj.h
no message
[wxWidgets.git] / include / wx / gtk1 / 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 wxString GetFiles() const;
188
189 virtual wxDataFormat GetPreferredFormat() const
190 { return wxDF_FILENAME; }
191 virtual bool IsSupportedFormat(const wxDataFormat& format) const
192 { return format == wxDF_FILENAME; }
193
194 virtual size_t GetDataSize(const wxDataFormat& format) const;
195 virtual bool GetDataHere(const wxDataFormat& format, void *buf) const;
196 virtual bool SetData(const wxDataFormat& format, const void *buf);
197
198 public:
199 wxString m_files;
200
201 private:
202 DECLARE_DYNAMIC_CLASS( wxFileDataObject )
203 };
204
205 //----------------------------------------------------------------------------
206 // wxBitmapDataObject is a specialization of wxDataObject for bitmaps
207 //----------------------------------------------------------------------------
208
209 class wxBitmapDataObject : public wxDataObject
210 {
211 public:
212 // ctors
213 wxBitmapDataObject();
214 wxBitmapDataObject(const wxBitmap& bitmap);
215
216 // destr
217 ~wxBitmapDataObject();
218
219 // set/get our bitmap
220 void SetBitmap(const wxBitmap& bitmap);
221 const wxBitmap GetBitmap() const { return m_bitmap; }
222
223 virtual wxDataFormat GetPreferredFormat() const
224 { return wxDF_BITMAP; }
225 virtual bool IsSupportedFormat(const wxDataFormat& format) const
226 { return format == wxDF_BITMAP; }
227
228 virtual size_t GetDataSize(const wxDataFormat& format) const;
229 virtual bool GetDataHere(const wxDataFormat& format, void *buf) const;
230
231 // sets PNG data
232 virtual bool SetData(const wxDataFormat& format, const void *buf);
233
234 // sets PNG data
235 virtual void SetPngData(const void *buf, size_t size);
236
237 void *GetData()
238 { return m_pngData; }
239
240 private:
241 wxBitmap m_bitmap;
242 size_t m_pngSize;
243 void *m_pngData;
244
245 void DoConvertToPng();
246
247 private:
248 DECLARE_DYNAMIC_CLASS( wxBitmapDataObject );
249 };
250
251 #endif
252 //__GTKDNDH__
253