]>
Commit | Line | Data |
---|---|---|
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 |
26 | class wxDataFormat; |
27 | class wxDataBroker; | |
8b53e5a2 RR |
28 | class wxDataObject; |
29 | class wxTextDataObject; | |
30 | class wxBitmapDataObject; | |
31 | class wxPrivateDataObject; | |
32 | class wxFileDataObject; | |
33 | ||
f37615d7 | 34 | //------------------------------------------------------------------------- |
1dd989e1 | 35 | // wxDataFormat |
f37615d7 RR |
36 | //------------------------------------------------------------------------- |
37 | ||
1dd989e1 | 38 | class wxDataFormat |
0d2a2b60 | 39 | { |
8b53e5a2 | 40 | public: |
1dd989e1 RR |
41 | // the clipboard formats under GDK are GdkAtoms |
42 | typedef GdkAtom NativeFormat; | |
43 | ||
3f480da3 VZ |
44 | wxDataFormat(); |
45 | wxDataFormat( wxDataFormatId type ); | |
46 | wxDataFormat( const wxString &id ); | |
47 | wxDataFormat( const wxChar *id ); | |
1dd989e1 RR |
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 ); | |
3f480da3 | 77 | |
1dd989e1 RR |
78 | // this only works with standard ids |
79 | void SetId( NativeFormat format ); | |
3f480da3 | 80 | |
1dd989e1 RR |
81 | // string ids are used for custom types - this SetId() must be used for |
82 | // application-specific formats | |
3f480da3 VZ |
83 | wxString GetId() const; |
84 | void SetId( const wxChar *id ); | |
85 | ||
1dd989e1 RR |
86 | // implementation |
87 | wxDataFormatId GetType() const; | |
9726da4f | 88 | |
3f480da3 | 89 | private: |
1dd989e1 RR |
90 | wxDataFormatId m_type; |
91 | NativeFormat m_format; | |
e2acb9ae RR |
92 | |
93 | void PrepareFormats(); | |
1dd989e1 | 94 | void SetType( wxDataFormatId type ); |
8b53e5a2 RR |
95 | }; |
96 | ||
0d2a2b60 | 97 | //---------------------------------------------------------------------------- |
1dd989e1 | 98 | // wxDataObject |
0d2a2b60 RR |
99 | //---------------------------------------------------------------------------- |
100 | ||
101 | class wxDataObject : public wxObject | |
102 | { | |
0d2a2b60 | 103 | public: |
e2acb9ae | 104 | wxDataObject(); |
e2acb9ae | 105 | ~wxDataObject(); |
e2acb9ae | 106 | |
1dd989e1 RR |
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(); } | |
3f480da3 | 135 | |
1dd989e1 RR |
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; | |
3f480da3 | 140 | |
e2acb9ae RR |
141 | private: |
142 | DECLARE_DYNAMIC_CLASS( wxDataObject ) | |
0d2a2b60 RR |
143 | }; |
144 | ||
145 | //---------------------------------------------------------------------------- | |
8b53e5a2 | 146 | // wxTextDataObject is a specialization of wxDataObject for text data |
0d2a2b60 | 147 | //---------------------------------------------------------------------------- |
8b53e5a2 RR |
148 | |
149 | class wxTextDataObject : public wxDataObject | |
150 | { | |
8b53e5a2 | 151 | public: |
1dd989e1 | 152 | // ctors |
e2acb9ae | 153 | wxTextDataObject(); |
1dd989e1 RR |
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; } | |
8b53e5a2 | 169 | |
1dd989e1 RR |
170 | private: |
171 | wxString m_strText; | |
172 | ||
e2acb9ae RR |
173 | private: |
174 | DECLARE_DYNAMIC_CLASS( wxTextDataObject ) | |
8b53e5a2 RR |
175 | }; |
176 | ||
0d2a2b60 | 177 | //---------------------------------------------------------------------------- |
8b53e5a2 | 178 | // wxFileDataObject is a specialization of wxDataObject for file names |
0d2a2b60 | 179 | //---------------------------------------------------------------------------- |
8b53e5a2 RR |
180 | |
181 | class wxFileDataObject : public wxDataObject | |
182 | { | |
8b53e5a2 | 183 | public: |
e2acb9ae | 184 | wxFileDataObject(); |
1dd989e1 | 185 | |
e2acb9ae | 186 | void AddFile( const wxString &file ); |
8e00741d RR |
187 | void SetFiles( const wxString &files ) |
188 | { m_files = files; } | |
e2acb9ae | 189 | wxString GetFiles() const; |
1dd989e1 RR |
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); | |
3f480da3 | 199 | |
e2acb9ae | 200 | public: |
e2acb9ae RR |
201 | wxString m_files; |
202 | ||
203 | private: | |
204 | DECLARE_DYNAMIC_CLASS( wxFileDataObject ) | |
8b53e5a2 RR |
205 | }; |
206 | ||
0d2a2b60 | 207 | //---------------------------------------------------------------------------- |
8b53e5a2 | 208 | // wxBitmapDataObject is a specialization of wxDataObject for bitmaps |
0d2a2b60 | 209 | //---------------------------------------------------------------------------- |
8b53e5a2 RR |
210 | |
211 | class wxBitmapDataObject : public wxDataObject | |
212 | { | |
8b53e5a2 | 213 | public: |
1dd989e1 | 214 | // ctors |
e2acb9ae | 215 | wxBitmapDataObject(); |
1dd989e1 | 216 | wxBitmapDataObject(const wxBitmap& bitmap); |
e2acb9ae | 217 | |
1dd989e1 RR |
218 | // destr |
219 | ~wxBitmapDataObject(); | |
e2acb9ae | 220 | |
1dd989e1 RR |
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); | |
e2acb9ae | 235 | |
1dd989e1 RR |
236 | // sets PNG data |
237 | virtual void SetPngData(const void *buf, size_t size); | |
238 | ||
239 | void *GetData() | |
240 | { return m_pngData; } | |
241 | ||
e2acb9ae RR |
242 | private: |
243 | wxBitmap m_bitmap; | |
244 | size_t m_pngSize; | |
1dd989e1 | 245 | void *m_pngData; |
e2acb9ae RR |
246 | |
247 | void DoConvertToPng(); | |
248 | ||
249 | private: | |
250 | DECLARE_DYNAMIC_CLASS( wxBitmapDataObject ); | |
8b53e5a2 RR |
251 | }; |
252 | ||
3f480da3 | 253 | #endif |
8b53e5a2 RR |
254 | //__GTKDNDH__ |
255 |