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 //-------------------------------------------------------------------------
40 //-------------------------------------------------------------------------
42 class WXDLLEXPORT wxDataObject
: public wxObject
45 // all data formats (values are the same as in windows.h, do not change!)
68 // function to return symbolic name of clipboard format (debug messages)
69 static const char *GetFormatName(wxDataFormat format
);
75 // pure virtuals to override
76 // get the best suited format for our data
77 virtual wxDataFormat
GetPreferredFormat() const = 0;
78 // decide if we support this format (should be one of values of
79 // StdFormat enumerations or a user-defined format)
80 virtual bool IsSupportedFormat(wxDataFormat format
) const = 0;
81 // get the (total) size of data
82 virtual size_t GetDataSize() const = 0;
83 // copy raw data to provided pointer
84 virtual void GetDataHere(void *pBuf
) const = 0;
88 // ----------------------------------------------------------------------------
89 // wxTextDataObject is a specialization of wxDataObject for text data
90 // ----------------------------------------------------------------------------
92 class WXDLLEXPORT wxTextDataObject
: public wxDataObject
96 wxTextDataObject() { }
97 wxTextDataObject(const wxString
& strText
) : m_strText(strText
) { }
98 void Init(const wxString
& strText
) { m_strText
= strText
; }
100 // implement base class pure virtuals
101 virtual wxDataFormat
GetPreferredFormat() const
102 { return wxDF_TEXT
; }
103 virtual bool IsSupportedFormat(wxDataFormat format
) const
104 { return format
== wxDF_TEXT
; }
105 virtual size_t GetDataSize() const
106 { return m_strText
.Len() + 1; } // +1 for trailing '\0'of course
107 virtual void GetDataHere(void *pBuf
) const
108 { memcpy(pBuf
, m_strText
.c_str(), GetDataSize()); }
115 // ----------------------------------------------------------------------------
116 // wxFileDataObject is a specialization of wxDataObject for file names
117 // ----------------------------------------------------------------------------
119 class WXDLLEXPORT wxFileDataObject
: public wxDataObject
123 wxFileDataObject(void) { }
124 void AddFile( const wxString
&file
)
125 { m_files
+= file
; m_files
+= ";"; }
127 // implement base class pure virtuals
128 virtual wxDataFormat
GetPreferredFormat() const
129 { return wxDF_FILENAME
; }
130 virtual bool IsSupportedFormat(wxDataFormat format
) const
131 { return format
== wxDF_FILENAME
; }
132 virtual size_t GetDataSize() const
133 { return m_files
.Len() + 1; } // +1 for trailing '\0'of course
134 virtual void GetDataHere(void *pBuf
) const
135 { memcpy(pBuf
, m_files
.c_str(), GetDataSize()); }
141 //-------------------------------------------------------------------------
143 //-------------------------------------------------------------------------
145 class WXDLLEXPORT wxDropTarget
: public wxObject
152 virtual void OnEnter() { }
153 virtual void OnLeave() { }
154 virtual bool OnDrop( long x
, long y
, const void *pData
) = 0;
160 // Override these to indicate what kind of data you support:
162 virtual size_t GetFormatCount() const = 0;
163 virtual wxDataFormat
GetFormat(size_t n
) const = 0;
166 //-------------------------------------------------------------------------
168 //-------------------------------------------------------------------------
170 class WXDLLEXPORT wxTextDropTarget
: public wxDropTarget
174 wxTextDropTarget() {};
175 virtual bool OnDrop( long x
, long y
, const void *pData
);
176 virtual bool OnDropText( long x
, long y
, const char *psz
);
180 virtual size_t GetFormatCount() const;
181 virtual wxDataFormat
GetFormat(size_t n
) const;
184 // ----------------------------------------------------------------------------
185 // A drop target which accepts files (dragged from File Manager or Explorer)
186 // ----------------------------------------------------------------------------
188 class WXDLLEXPORT wxFileDropTarget
: public wxDropTarget
192 wxFileDropTarget() {};
194 virtual bool OnDrop(long x
, long y
, const void *pData
);
195 virtual bool OnDropFiles( long x
, long y
,
196 size_t nFiles
, const char * const aszFiles
[]);
200 virtual size_t GetFormatCount() const;
201 virtual wxDataFormat
GetFormat(size_t n
) const;
204 //-------------------------------------------------------------------------
206 //-------------------------------------------------------------------------
210 wxDragError
, // error prevented the d&d operation from completing
211 wxDragNone
, // drag target didn't accept the data
212 wxDragCopy
, // the data was successfully copied
213 wxDragMove
, // the data was successfully moved
214 wxDragCancel
// the operation was cancelled by user (not an error)
217 class WXDLLEXPORT wxDropSource
: public wxObject
221 wxDropSource( wxWindow
*win
);
222 wxDropSource( wxDataObject
&data
, wxWindow
*win
);
226 void SetData( wxDataObject
&data
);
227 wxDragResult
DoDragDrop( bool bAllowMove
= FALSE
);
229 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
), bool WXUNUSED(bScrolling
) ) { return TRUE
; };
233 wxDataObject
*m_data
;