]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/dnd.h
Added wxImage wxImage::GetSubImage(cont wxRect&) const
[wxWidgets.git] / include / wx / os2 / dnd.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: dnd.h
3 // Purpose: Declaration of the wxDropTarget, wxDropSource class etc.
4 // Author: AUTHOR
5 // RCS-ID: $Id$
6 // Copyright: (c) 1998 AUTHOR
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_DND_H_
11 #define _WX_DND_H_
12
13 #ifdef __GNUG__
14 #pragma interface "dnd.h"
15 #endif
16
17 #include "wx/defs.h"
18 #include "wx/object.h"
19 #include "wx/string.h"
20 #include "wx/cursor.h"
21
22 //-------------------------------------------------------------------------
23 // classes
24 //-------------------------------------------------------------------------
25
26 class WXDLLEXPORT wxWindow;
27
28 class WXDLLEXPORT wxDataObject;
29 class WXDLLEXPORT wxTextDataObject;
30 class WXDLLEXPORT wxFileDataObject;
31
32 class WXDLLEXPORT wxDropTarget;
33 class WXDLLEXPORT wxTextDropTarget;
34 class WXDLLEXPORT wxFileDropTarget;
35
36 class WXDLLEXPORT wxDropSource;
37
38 //-------------------------------------------------------------------------
39 // wxDataFormat (internal)
40 //-------------------------------------------------------------------------
41
42 class wxDataFormat : public wxObject
43 {
44 DECLARE_CLASS( wxDataFormat )
45
46 public:
47 wxDataFormat();
48 wxDataFormat( wxDataFormatId type );
49 wxDataFormat( const wxString &id );
50 wxDataFormat( const wxChar *id );
51 wxDataFormat( const wxDataFormat &format );
52
53 void SetType( wxDataFormatId type );
54 wxDataFormatId GetType() const;
55
56 /* the string Id identifies the format of clipboard or DnD data. a word
57 * processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
58 * to the clipboard - the latter with the Id "application/wxword", an
59 * image manipulation program would put a wxBitmapDataObject and a
60 * wxPrivateDataObject to the clipboard - the latter with "image/png". */
61
62 wxString GetId() const;
63 void SetId( const wxChar *id );
64
65 // implicit conversion to wxDataFormatId
66 operator wxDataFormatId() const { return m_type; }
67
68 bool operator==(wxDataFormatId type) const { return m_type == type; }
69 bool operator!=(wxDataFormatId type) const { return m_type != type; }
70
71 private:
72 wxDataFormatId m_type;
73 wxString m_id;
74 };
75
76 //-------------------------------------------------------------------------
77 // wxDataBroker (internal)
78 //-------------------------------------------------------------------------
79
80 class wxDataBroker : public wxObject
81 {
82 DECLARE_CLASS( wxDataBroker )
83
84 public:
85
86 /* constructor */
87 wxDataBroker();
88
89 /* add data object */
90 void Add( wxDataObject *dataObject, bool preferred = FALSE );
91
92 private:
93
94 /* OLE implementation, the methods don't need to be overridden */
95
96 /* get number of supported formats */
97 virtual size_t GetFormatCount() const;
98
99 /* return nth supported format */
100 virtual wxDataFormat &GetNthFormat( size_t nth ) const;
101
102 /* return preferrd/best supported format */
103 virtual wxDataFormatId GetPreferredFormat() const;
104
105 /* search through m_dataObjects, return TRUE if found */
106 virtual bool IsSupportedFormat( wxDataFormat &format ) const;
107
108 /* search through m_dataObjects and call child's GetSize() */
109 virtual size_t GetSize( wxDataFormat& format ) const;
110
111 /* search through m_dataObjects and call child's WriteData(dest) */
112 virtual void WriteData( wxDataFormat& format, void *dest ) const;
113
114 /* implementation */
115
116 public:
117
118 wxList m_dataObjects;
119 size_t m_preferred;
120 };
121
122 //-------------------------------------------------------------------------
123 // wxDataObject
124 //-------------------------------------------------------------------------
125
126 class WXDLLEXPORT wxDataObject: public wxObject
127 {
128 public:
129 // all data formats (values are the same as in windows.h, do not change!)
130 enum StdFormat
131 {
132 Invalid,
133 Text,
134 Bitmap,
135 MetafilePict,
136 Sylk,
137 Dif,
138 Tiff,
139 OemText,
140 Dib,
141 Palette,
142 Pendata,
143 Riff,
144 Wave,
145 UnicodeText,
146 EnhMetafile,
147 Hdrop,
148 Locale,
149 Max
150 };
151
152 // function to return symbolic name of clipboard format (debug messages)
153 static const char *GetFormatName(wxDataFormat format);
154
155 // ctor & dtor
156 wxDataObject() {};
157 ~wxDataObject() {};
158
159 // pure virtuals to override
160 // get the best suited format for our data
161 virtual wxDataFormat GetPreferredFormat() const = 0;
162 // decide if we support this format (should be one of values of
163 // StdFormat enumerations or a user-defined format)
164 virtual bool IsSupportedFormat(wxDataFormat format) const = 0;
165 // get the (total) size of data
166 virtual size_t GetDataSize() const = 0;
167 // copy raw data to provided pointer
168 virtual void GetDataHere(void *pBuf) const = 0;
169
170 };
171
172 // ----------------------------------------------------------------------------
173 // wxTextDataObject is a specialization of wxDataObject for text data
174 // ----------------------------------------------------------------------------
175
176 class WXDLLEXPORT wxTextDataObject : public wxDataObject
177 {
178 public:
179 // ctors
180 wxTextDataObject() { }
181 wxTextDataObject(const wxString& strText) : m_strText(strText) { }
182 void Init(const wxString& strText) { m_strText = strText; }
183
184 // implement base class pure virtuals
185 virtual wxDataFormat GetPreferredFormat() const
186 { return wxDF_TEXT; }
187 virtual bool IsSupportedFormat(wxDataFormat format) const
188 { return format == wxDF_TEXT; }
189 virtual size_t GetDataSize() const
190 { return m_strText.Len() + 1; } // +1 for trailing '\0'of course
191 virtual void GetDataHere(void *pBuf) const
192 { memcpy(pBuf, m_strText.c_str(), GetDataSize()); }
193
194 private:
195 wxString m_strText;
196
197 };
198
199 // ----------------------------------------------------------------------------
200 // wxFileDataObject is a specialization of wxDataObject for file names
201 // ----------------------------------------------------------------------------
202
203 class WXDLLEXPORT wxFileDataObject : public wxDataObject
204 {
205 public:
206
207 wxFileDataObject(void) { }
208 void AddFile( const wxString &file )
209 { m_files += file; m_files += ";"; }
210
211 // implement base class pure virtuals
212 virtual wxDataFormat GetPreferredFormat() const
213 { return wxDF_FILENAME; }
214 virtual bool IsSupportedFormat(wxDataFormat format) const
215 { return format == wxDF_FILENAME; }
216 virtual size_t GetDataSize() const
217 { return m_files.Len() + 1; } // +1 for trailing '\0'of course
218 virtual void GetDataHere(void *pBuf) const
219 { memcpy(pBuf, m_files.c_str(), GetDataSize()); }
220
221 private:
222 wxString m_files;
223
224 };
225 //-------------------------------------------------------------------------
226 // wxDropTarget
227 //-------------------------------------------------------------------------
228
229 class WXDLLEXPORT wxDropTarget: public wxObject
230 {
231 public:
232
233 wxDropTarget();
234 ~wxDropTarget();
235
236 virtual void OnEnter() { }
237 virtual void OnLeave() { }
238 virtual bool OnDrop( long x, long y, const void *pData ) = 0;
239
240 // protected:
241
242 friend wxWindow;
243
244 // Override these to indicate what kind of data you support:
245
246 virtual size_t GetFormatCount() const = 0;
247 virtual wxDataFormat GetFormat(size_t n) const = 0;
248 };
249
250 //-------------------------------------------------------------------------
251 // wxTextDropTarget
252 //-------------------------------------------------------------------------
253
254 class WXDLLEXPORT wxTextDropTarget: public wxDropTarget
255 {
256 public:
257
258 wxTextDropTarget() {};
259 virtual bool OnDrop( long x, long y, const void *pData );
260 virtual bool OnDropText( long x, long y, const char *psz );
261
262 protected:
263
264 virtual size_t GetFormatCount() const;
265 virtual wxDataFormat GetFormat(size_t n) const;
266 };
267
268 // ----------------------------------------------------------------------------
269 // A drop target which accepts files (dragged from File Manager or Explorer)
270 // ----------------------------------------------------------------------------
271
272 class WXDLLEXPORT wxFileDropTarget: public wxDropTarget
273 {
274 public:
275
276 wxFileDropTarget() {};
277
278 virtual bool OnDrop(long x, long y, const void *pData);
279 virtual bool OnDropFiles( long x, long y,
280 size_t nFiles, const char * const aszFiles[]);
281
282 protected:
283
284 virtual size_t GetFormatCount() const;
285 virtual wxDataFormat GetFormat(size_t n) const;
286 };
287
288 //-------------------------------------------------------------------------
289 // wxDropSource
290 //-------------------------------------------------------------------------
291
292 enum wxDragResult
293 {
294 wxDragError, // error prevented the d&d operation from completing
295 wxDragNone, // drag target didn't accept the data
296 wxDragCopy, // the data was successfully copied
297 wxDragMove, // the data was successfully moved
298 wxDragCancel // the operation was cancelled by user (not an error)
299 };
300
301 class WXDLLEXPORT wxDropSource: public wxObject
302 {
303 public:
304
305 wxDropSource( wxWindow *win );
306 wxDropSource( wxDataObject &data, wxWindow *win );
307
308 ~wxDropSource(void);
309
310 void SetData( wxDataObject &data );
311 wxDragResult DoDragDrop( bool bAllowMove = FALSE );
312
313 virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; };
314
315 protected:
316
317 wxDataObject *m_data;
318 };
319
320 #endif
321 //_WX_DND_H_
322