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
;
75 //-------------------------------------------------------------------------
77 //-------------------------------------------------------------------------
79 class WXDLLEXPORT wxDataObject
: public wxObject
82 // all data formats (values are the same as in windows.h, do not change!)
105 // function to return symbolic name of clipboard format (debug messages)
106 static const char *GetFormatName(wxDataFormat format
);
112 // pure virtuals to override
113 // get the best suited format for our data
114 virtual wxDataFormat
GetPreferredFormat() const = 0;
115 // decide if we support this format (should be one of values of
116 // StdFormat enumerations or a user-defined format)
117 virtual bool IsSupportedFormat(wxDataFormat format
) const = 0;
118 // get the (total) size of data
119 virtual size_t GetDataSize() const = 0;
120 // copy raw data to provided pointer
121 virtual void GetDataHere(void *pBuf
) const = 0;
125 // ----------------------------------------------------------------------------
126 // wxTextDataObject is a specialization of wxDataObject for text data
127 // ----------------------------------------------------------------------------
129 class WXDLLEXPORT wxTextDataObject
: public wxDataObject
133 wxTextDataObject() { }
134 wxTextDataObject(const wxString
& strText
) : m_strText(strText
) { }
135 void Init(const wxString
& strText
) { m_strText
= strText
; }
137 // implement base class pure virtuals
138 virtual wxDataFormat
GetPreferredFormat() const
139 { return wxDF_TEXT
; }
140 virtual bool IsSupportedFormat(wxDataFormat format
) const
141 { return format
== wxDF_TEXT
; }
142 virtual size_t GetDataSize() const
143 { return m_strText
.Len() + 1; } // +1 for trailing '\0'of course
144 virtual void GetDataHere(void *pBuf
) const
145 { memcpy(pBuf
, m_strText
.c_str(), GetDataSize()); }
152 // ----------------------------------------------------------------------------
153 // wxFileDataObject is a specialization of wxDataObject for file names
154 // ----------------------------------------------------------------------------
156 class WXDLLEXPORT wxFileDataObject
: public wxDataObject
160 wxFileDataObject(void) { }
161 void AddFile( const wxString
&file
)
162 { m_files
+= file
; m_files
+= ";"; }
164 // implement base class pure virtuals
165 virtual wxDataFormat
GetPreferredFormat() const
166 { return wxDF_FILENAME
; }
167 virtual bool IsSupportedFormat(wxDataFormat format
) const
168 { return format
== wxDF_FILENAME
; }
169 virtual size_t GetDataSize() const
170 { return m_files
.Len() + 1; } // +1 for trailing '\0'of course
171 virtual void GetDataHere(void *pBuf
) const
172 { memcpy(pBuf
, m_files
.c_str(), GetDataSize()); }
178 //-------------------------------------------------------------------------
180 //-------------------------------------------------------------------------
182 class WXDLLEXPORT wxDropTarget
: public wxObject
189 virtual void OnEnter() { }
190 virtual void OnLeave() { }
191 virtual bool OnDrop( long x
, long y
, const void *pData
) = 0;
197 // Override these to indicate what kind of data you support:
199 virtual size_t GetFormatCount() const = 0;
200 virtual wxDataFormat
GetFormat(size_t n
) const = 0;
203 //-------------------------------------------------------------------------
205 //-------------------------------------------------------------------------
207 class WXDLLEXPORT wxTextDropTarget
: public wxDropTarget
211 wxTextDropTarget() {};
212 virtual bool OnDrop( long x
, long y
, const void *pData
);
213 virtual bool OnDropText( long x
, long y
, const char *psz
);
217 virtual size_t GetFormatCount() const;
218 virtual wxDataFormat
GetFormat(size_t n
) const;
221 // ----------------------------------------------------------------------------
222 // A drop target which accepts files (dragged from File Manager or Explorer)
223 // ----------------------------------------------------------------------------
225 class WXDLLEXPORT wxFileDropTarget
: public wxDropTarget
229 wxFileDropTarget() {};
231 virtual bool OnDrop(long x
, long y
, const void *pData
);
232 virtual bool OnDropFiles( long x
, long y
,
233 size_t nFiles
, const char * const aszFiles
[]);
237 virtual size_t GetFormatCount() const;
238 virtual wxDataFormat
GetFormat(size_t n
) const;
241 //-------------------------------------------------------------------------
243 //-------------------------------------------------------------------------
247 wxDragError
, // error prevented the d&d operation from completing
248 wxDragNone
, // drag target didn't accept the data
249 wxDragCopy
, // the data was successfully copied
250 wxDragMove
, // the data was successfully moved
251 wxDragCancel
// the operation was cancelled by user (not an error)
254 class WXDLLEXPORT wxDropSource
: public wxObject
258 wxDropSource( wxWindow
*win
);
259 wxDropSource( wxDataObject
&data
, wxWindow
*win
);
263 void SetData( wxDataObject
&data
);
264 wxDragResult
DoDragDrop( bool bAllowMove
= FALSE
);
266 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
), bool WXUNUSED(bScrolling
) ) { return TRUE
; };
270 wxDataObject
*m_data
;