1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: Declaration of the wxDropTarget, wxDropSource class etc.
6 // Copyright: (c) 1998 AUTHOR
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
14 #pragma interface "dnd.h"
18 #include "wx/object.h"
19 #include "wx/string.h"
20 #include "wx/cursor.h"
22 //-------------------------------------------------------------------------
24 //-------------------------------------------------------------------------
26 class WXDLLEXPORT wxWindow
;
28 class WXDLLEXPORT wxDataObject
;
29 class WXDLLEXPORT wxTextDataObject
;
30 class WXDLLEXPORT wxFileDataObject
;
32 class WXDLLEXPORT wxDropTarget
;
33 class WXDLLEXPORT wxTextDropTarget
;
34 class WXDLLEXPORT wxFileDropTarget
;
36 class WXDLLEXPORT wxDropSource
;
38 //-------------------------------------------------------------------------
39 // wxDataFormat (internal)
40 //-------------------------------------------------------------------------
42 class wxDataFormat
: public wxObject
44 DECLARE_CLASS( wxDataFormat
)
48 wxDataFormat( wxDataFormatId type
);
49 wxDataFormat( const wxString
&id
);
50 wxDataFormat( const wxChar
*id
);
51 wxDataFormat( const wxDataFormat
&format
);
53 void SetType( wxDataFormatId type
);
54 wxDataFormatId
GetType() const;
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". */
62 wxString
GetId() const;
63 void SetId( const wxChar
*id
);
65 // implicit conversion to wxDataFormatId
66 operator wxDataFormatId() const { return m_type
; }
68 bool operator==(wxDataFormatId type
) const { return m_type
== type
; }
69 bool operator!=(wxDataFormatId type
) const { return m_type
!= type
; }
72 wxDataFormatId m_type
;
76 //-------------------------------------------------------------------------
77 // wxDataBroker (internal)
78 //-------------------------------------------------------------------------
80 class wxDataBroker
: public wxObject
82 DECLARE_CLASS( wxDataBroker
)
90 void Add( wxDataObject
*dataObject
, bool preferred
= FALSE
);
94 /* OLE implementation, the methods don't need to be overridden */
96 /* get number of supported formats */
97 virtual size_t GetFormatCount() const;
99 /* return nth supported format */
100 virtual wxDataFormat
&GetNthFormat( size_t nth
) const;
102 /* return preferrd/best supported format */
103 virtual wxDataFormatId
GetPreferredFormat() const;
105 /* search through m_dataObjects, return TRUE if found */
106 virtual bool IsSupportedFormat( wxDataFormat
&format
) const;
108 /* search through m_dataObjects and call child's GetSize() */
109 virtual size_t GetSize( wxDataFormat
& format
) const;
111 /* search through m_dataObjects and call child's WriteData(dest) */
112 virtual void WriteData( wxDataFormat
& format
, void *dest
) const;
118 wxList m_dataObjects
;
122 //-------------------------------------------------------------------------
124 //-------------------------------------------------------------------------
126 class WXDLLEXPORT wxDataObject
: public wxObject
129 // all data formats (values are the same as in windows.h, do not change!)
152 // function to return symbolic name of clipboard format (debug messages)
153 static const char *GetFormatName(wxDataFormat format
);
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;
172 // ----------------------------------------------------------------------------
173 // wxTextDataObject is a specialization of wxDataObject for text data
174 // ----------------------------------------------------------------------------
176 class WXDLLEXPORT wxTextDataObject
: public wxDataObject
180 wxTextDataObject() { }
181 wxTextDataObject(const wxString
& strText
) : m_strText(strText
) { }
182 void Init(const wxString
& strText
) { m_strText
= strText
; }
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()); }
199 // ----------------------------------------------------------------------------
200 // wxFileDataObject is a specialization of wxDataObject for file names
201 // ----------------------------------------------------------------------------
203 class WXDLLEXPORT wxFileDataObject
: public wxDataObject
207 wxFileDataObject(void) { }
208 void AddFile( const wxString
&file
)
209 { m_files
+= file
; m_files
+= ";"; }
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()); }
225 //-------------------------------------------------------------------------
227 //-------------------------------------------------------------------------
229 class WXDLLEXPORT wxDropTarget
: public wxObject
236 virtual void OnEnter() { }
237 virtual void OnLeave() { }
238 virtual bool OnDrop( long x
, long y
, const void *pData
) = 0;
244 // Override these to indicate what kind of data you support:
246 virtual size_t GetFormatCount() const = 0;
247 virtual wxDataFormat
GetFormat(size_t n
) const = 0;
250 //-------------------------------------------------------------------------
252 //-------------------------------------------------------------------------
254 class WXDLLEXPORT wxTextDropTarget
: public wxDropTarget
258 wxTextDropTarget() {};
259 virtual bool OnDrop( long x
, long y
, const void *pData
);
260 virtual bool OnDropText( long x
, long y
, const char *psz
);
264 virtual size_t GetFormatCount() const;
265 virtual wxDataFormat
GetFormat(size_t n
) const;
268 // ----------------------------------------------------------------------------
269 // A drop target which accepts files (dragged from File Manager or Explorer)
270 // ----------------------------------------------------------------------------
272 class WXDLLEXPORT wxFileDropTarget
: public wxDropTarget
276 wxFileDropTarget() {};
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
[]);
284 virtual size_t GetFormatCount() const;
285 virtual wxDataFormat
GetFormat(size_t n
) const;
288 //-------------------------------------------------------------------------
290 //-------------------------------------------------------------------------
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)
301 class WXDLLEXPORT wxDropSource
: public wxObject
305 wxDropSource( wxWindow
*win
);
306 wxDropSource( wxDataObject
&data
, wxWindow
*win
);
310 void SetData( wxDataObject
&data
);
311 wxDragResult
DoDragDrop( bool bAllowMove
= FALSE
);
313 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
), bool WXUNUSED(bScrolling
) ) { return TRUE
; };
317 wxDataObject
*m_data
;