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
;
29 class WXDLLEXPORT wxDataObject
;
30 class WXDLLEXPORT wxTextDataObject
;
31 class WXDLLEXPORT wxFileDataObject
;
34 class WXDLLEXPORT wxDropTarget
;
35 class WXDLLEXPORT wxTextDropTarget
;
36 class WXDLLEXPORT wxFileDropTarget
;
38 class WXDLLEXPORT wxDropSource
;
41 //-------------------------------------------------------------------------
43 //-------------------------------------------------------------------------
45 class WXDLLEXPORT wxDataObject
: public wxObject
48 // all data formats (values are the same as in windows.h, do not change!)
71 // function to return symbolic name of clipboard format (debug messages)
72 static const char *GetFormatName(wxDataFormat format
);
78 // pure virtuals to override
79 // get the best suited format for our data
80 virtual wxDataFormat
GetPreferredFormat() const = 0;
81 // decide if we support this format (should be one of values of
82 // StdFormat enumerations or a user-defined format)
83 virtual bool IsSupportedFormat(wxDataFormat format
) const = 0;
84 // get the (total) size of data
85 virtual size_t GetDataSize() const = 0;
86 // copy raw data to provided pointer
87 virtual void GetDataHere(void *pBuf
) const = 0;
91 // ----------------------------------------------------------------------------
92 // wxTextDataObject is a specialization of wxDataObject for text data
93 // ----------------------------------------------------------------------------
95 class WXDLLEXPORT wxTextDataObject
: public wxDataObject
99 wxTextDataObject() { }
100 wxTextDataObject(const wxString
& strText
) : m_strText(strText
) { }
101 void Init(const wxString
& strText
) { m_strText
= strText
; }
103 // implement base class pure virtuals
104 virtual wxDataFormat
GetPreferredFormat() const
105 { return wxDF_TEXT
; }
106 virtual bool IsSupportedFormat(wxDataFormat format
) const
107 { return format
== wxDF_TEXT
; }
108 virtual size_t GetDataSize() const
109 { return m_strText
.Len() + 1; } // +1 for trailing '\0'of course
110 virtual void GetDataHere(void *pBuf
) const
111 { memcpy(pBuf
, m_strText
.c_str(), GetDataSize()); }
118 // ----------------------------------------------------------------------------
119 // wxFileDataObject is a specialization of wxDataObject for file names
120 // ----------------------------------------------------------------------------
122 class WXDLLEXPORT wxFileDataObject
: public wxDataObject
126 wxFileDataObject(void) { }
127 void AddFile( const wxString
&file
)
128 { m_files
+= file
; m_files
+= ";"; }
130 // implement base class pure virtuals
131 virtual wxDataFormat
GetPreferredFormat() const
132 { return wxDF_FILENAME
; }
133 virtual bool IsSupportedFormat(wxDataFormat format
) const
134 { return format
== wxDF_FILENAME
; }
135 virtual size_t GetDataSize() const
136 { return m_files
.Len() + 1; } // +1 for trailing '\0'of course
137 virtual void GetDataHere(void *pBuf
) const
138 { memcpy(pBuf
, m_files
.c_str(), GetDataSize()); }
146 //-------------------------------------------------------------------------
148 //-------------------------------------------------------------------------
150 class WXDLLEXPORT wxDropTarget
: public wxObject
157 virtual void OnEnter() { }
158 virtual void OnLeave() { }
159 virtual bool OnDrop( wxCoord x
, wxCoord y
, const void *pData
) = 0;
163 friend class wxWindow
;
165 // Override these to indicate what kind of data you support:
167 virtual size_t GetFormatCount() const = 0;
168 virtual wxDataFormat
GetFormat(size_t n
) const = 0;
172 //-------------------------------------------------------------------------
174 //-------------------------------------------------------------------------
176 class WXDLLEXPORT wxTextDropTarget
: public wxDropTarget
180 wxTextDropTarget() {};
181 virtual bool OnDrop( wxCoord x
, wxCoord y
, const void *pData
);
182 virtual bool OnDropText( wxCoord x
, wxCoord y
, const char *psz
);
186 virtual size_t GetFormatCount() const;
187 virtual wxDataFormat
GetFormat(size_t n
) const;
190 // ----------------------------------------------------------------------------
191 // A drop target which accepts files (dragged from File Manager or Explorer)
192 // ----------------------------------------------------------------------------
194 class WXDLLEXPORT wxFileDropTarget
: public wxDropTarget
198 wxFileDropTarget() {};
200 virtual bool OnDrop(wxCoord x
, wxCoord y
, const void *pData
);
201 virtual bool OnDropFiles( wxCoord x
, wxCoord y
,
202 size_t nFiles
, const char * const aszFiles
[]);
206 virtual size_t GetFormatCount() const;
207 virtual wxDataFormat
GetFormat(size_t n
) const;
211 //-------------------------------------------------------------------------
213 //-------------------------------------------------------------------------
215 class WXDLLEXPORT wxDropSource
: public wxObject
219 wxDropSource( wxWindow
*win
);
220 wxDropSource( wxDataObject
&data
, wxWindow
*win
);
224 void SetData( wxDataObject
&data
);
225 wxDragResult
DoDragDrop( bool bAllowMove
= FALSE
);
227 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
), bool WXUNUSED(bScrolling
) ) { return TRUE
; };
231 wxDataObject
*m_data
;