]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/qt/dnd.h
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: declaration of the wxDropTarget class
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Vadim Zeitlin, Robert Roebling
7 // Licence: wxWindows license
8 ///////////////////////////////////////////////////////////////////////////////
19 #include "wx/object.h"
20 #include "wx/string.h"
21 #include "wx/cursor.h"
23 //-------------------------------------------------------------------------
25 //-------------------------------------------------------------------------
30 class wxTextDataObject
;
31 class wxFileDataObject
;
34 class wxTextDropTarget
;
35 class wxFileDropTarget
;
39 //-------------------------------------------------------------------------
41 //-------------------------------------------------------------------------
43 class wxDataObject
: public wxObject
46 // all data formats (values are the same as in windows.h, do not change!)
69 // function to return symbolic name of clipboard format (debug messages)
70 static const char *GetFormatName(wxDataFormat format
);
76 // pure virtuals to override
77 // get the best suited format for our data
78 virtual wxDataFormat
GetPreferredFormat() const = 0;
79 // decide if we support this format (should be one of values of
80 // StdFormat enumerations or a user-defined format)
81 virtual bool IsSupportedFormat(wxDataFormat format
) const = 0;
82 // get the (total) size of data
83 virtual size_t GetDataSize() const = 0;
84 // copy raw data to provided pointer
85 virtual void GetDataHere(void *pBuf
) const = 0;
89 // ----------------------------------------------------------------------------
90 // wxTextDataObject is a specialization of wxDataObject for text data
91 // ----------------------------------------------------------------------------
93 class wxTextDataObject
: public wxDataObject
97 wxTextDataObject() { }
98 wxTextDataObject(const wxString
& strText
) : m_strText(strText
) { }
99 void Init(const wxString
& strText
) { m_strText
= strText
; }
101 // implement base class pure virtuals
102 virtual wxDataFormat
GetPreferredFormat() const
103 { return wxDF_TEXT
; }
104 virtual bool IsSupportedFormat(wxDataFormat format
) const
105 { return format
== wxDF_TEXT
; }
106 virtual size_t GetDataSize() const
107 { return m_strText
.Len() + 1; } // +1 for trailing '\0'of course
108 virtual void GetDataHere(void *pBuf
) const
109 { memcpy(pBuf
, m_strText
.c_str(), GetDataSize()); }
116 // ----------------------------------------------------------------------------
117 // wxFileDataObject is a specialization of wxDataObject for file names
118 // ----------------------------------------------------------------------------
120 class wxFileDataObject
: public wxDataObject
124 wxFileDataObject(void) { }
125 void AddFile( const wxString
&file
)
126 { m_files
+= file
; m_files
+= ";"; }
128 // implement base class pure virtuals
129 virtual wxDataFormat
GetPreferredFormat() const
130 { return wxDF_FILENAME
; }
131 virtual bool IsSupportedFormat(wxDataFormat format
) const
132 { return format
== wxDF_FILENAME
; }
133 virtual size_t GetDataSize() const
134 { return m_files
.Len() + 1; } // +1 for trailing '\0'of course
135 virtual void GetDataHere(void *pBuf
) const
136 { memcpy(pBuf
, m_files
.c_str(), GetDataSize()); }
142 //-------------------------------------------------------------------------
144 //-------------------------------------------------------------------------
146 class wxDropTarget
: public wxObject
153 virtual void OnEnter() { }
154 virtual void OnLeave() { }
155 virtual bool OnDrop( long x
, long y
, const void *pData
) = 0;
161 // Override these to indicate what kind of data you support:
163 virtual size_t GetFormatCount() const = 0;
164 virtual wxDataFormat
GetFormat(size_t n
) const = 0;
167 //-------------------------------------------------------------------------
169 //-------------------------------------------------------------------------
171 class wxTextDropTarget
: public wxDropTarget
175 wxTextDropTarget() {};
176 virtual bool OnDrop( long x
, long y
, const void *pData
);
177 virtual bool OnDropText( long x
, long y
, const char *psz
);
181 virtual size_t GetFormatCount() const;
182 virtual wxDataFormat
GetFormat(size_t n
) const;
185 // ----------------------------------------------------------------------------
186 // A drop target which accepts files (dragged from File Manager or Explorer)
187 // ----------------------------------------------------------------------------
189 class wxFileDropTarget
: public wxDropTarget
193 wxFileDropTarget() {};
195 virtual bool OnDrop(long x
, long y
, const void *pData
);
196 virtual bool OnDropFiles( long x
, long y
,
197 size_t nFiles
, const char * const aszFiles
[]);
201 virtual size_t GetFormatCount() const;
202 virtual wxDataFormat
GetFormat(size_t n
) const;
205 //-------------------------------------------------------------------------
207 //-------------------------------------------------------------------------
209 class wxDropSource
: public wxObject
215 Error
, // error prevented the d&d operation from completing
216 None
, // drag target didn't accept the data
217 Copy
, // the data was successfully copied
218 Move
, // the data was successfully moved
219 Cancel
// the operation was cancelled by user (not an error)
222 wxDropSource( wxWindow
*win
);
223 wxDropSource( wxDataObject
&data
, wxWindow
*win
);
227 void SetData( wxDataObject
&data
);
228 DragResult
DoDragDrop( bool bAllowMove
= FALSE
);
230 virtual bool GiveFeedback( DragResult
WXUNUSED(effect
), bool WXUNUSED(bScrolling
) ) { return TRUE
; };
234 wxDataObject
*m_data
;