]> git.saurik.com Git - wxWidgets.git/blob - include/wx/qt/dnd.h
shows different SetCursor() calls
[wxWidgets.git] / include / wx / qt / dnd.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: dnd.h
3 // Purpose: declaration of the wxDropTarget class
4 // Author: Robert Roebling
5 // RCS-ID:
6 // Copyright: (c) 1998 Vadim Zeitlin, Robert Roebling
7 // Licence: wxWindows license
8 ///////////////////////////////////////////////////////////////////////////////
9
10
11 #ifndef __GTKDNDH__
12 #define __GTKDNDH__
13
14 #ifdef __GNUG__
15 #pragma interface
16 #endif
17
18 #include "wx/defs.h"
19 #include "wx/object.h"
20 #include "wx/string.h"
21 #include "wx/cursor.h"
22
23 //-------------------------------------------------------------------------
24 // classes
25 //-------------------------------------------------------------------------
26
27 class wxWindow;
28
29 class wxDataObject;
30 class wxTextDataObject;
31 class wxFileDataObject;
32
33 class wxDropTarget;
34 class wxTextDropTarget;
35 class wxFileDropTarget;
36
37 class wxDropSource;
38
39 //-------------------------------------------------------------------------
40 // wxDataObject
41 //-------------------------------------------------------------------------
42
43 class wxDataObject: public wxObject
44 {
45 public:
46 // all data formats (values are the same as in windows.h, do not change!)
47 enum StdFormat
48 {
49 Invalid,
50 Text,
51 Bitmap,
52 MetafilePict,
53 Sylk,
54 Dif,
55 Tiff,
56 OemText,
57 Dib,
58 Palette,
59 Pendata,
60 Riff,
61 Wave,
62 UnicodeText,
63 EnhMetafile,
64 Hdrop,
65 Locale,
66 Max
67 };
68
69 // function to return symbolic name of clipboard format (debug messages)
70 static const char *GetFormatName(wxDataFormat format);
71
72 // ctor & dtor
73 wxDataObject() {};
74 ~wxDataObject() {};
75
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;
86
87 };
88
89 // ----------------------------------------------------------------------------
90 // wxTextDataObject is a specialization of wxDataObject for text data
91 // ----------------------------------------------------------------------------
92
93 class wxTextDataObject : public wxDataObject
94 {
95 public:
96 // ctors
97 wxTextDataObject() { }
98 wxTextDataObject(const wxString& strText) : m_strText(strText) { }
99 void Init(const wxString& strText) { m_strText = strText; }
100
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()); }
110
111 private:
112 wxString m_strText;
113
114 };
115
116 // ----------------------------------------------------------------------------
117 // wxFileDataObject is a specialization of wxDataObject for file names
118 // ----------------------------------------------------------------------------
119
120 class wxFileDataObject : public wxDataObject
121 {
122 public:
123
124 wxFileDataObject(void) { }
125 void AddFile( const wxString &file )
126 { m_files += file; m_files += ";"; }
127
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()); }
137
138 private:
139 wxString m_files;
140
141 };
142 //-------------------------------------------------------------------------
143 // wxDropTarget
144 //-------------------------------------------------------------------------
145
146 class wxDropTarget: public wxObject
147 {
148 public:
149
150 wxDropTarget();
151 ~wxDropTarget();
152
153 virtual void OnEnter() { }
154 virtual void OnLeave() { }
155 virtual bool OnDrop( long x, long y, const void *pData ) = 0;
156
157 // protected:
158
159 friend wxWindow;
160
161 // Override these to indicate what kind of data you support:
162
163 virtual size_t GetFormatCount() const = 0;
164 virtual wxDataFormat GetFormat(size_t n) const = 0;
165 };
166
167 //-------------------------------------------------------------------------
168 // wxTextDropTarget
169 //-------------------------------------------------------------------------
170
171 class wxTextDropTarget: public wxDropTarget
172 {
173 public:
174
175 wxTextDropTarget() {};
176 virtual bool OnDrop( long x, long y, const void *pData );
177 virtual bool OnDropText( long x, long y, const char *psz );
178
179 protected:
180
181 virtual size_t GetFormatCount() const;
182 virtual wxDataFormat GetFormat(size_t n) const;
183 };
184
185 // ----------------------------------------------------------------------------
186 // A drop target which accepts files (dragged from File Manager or Explorer)
187 // ----------------------------------------------------------------------------
188
189 class wxFileDropTarget: public wxDropTarget
190 {
191 public:
192
193 wxFileDropTarget() {};
194
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[]);
198
199 protected:
200
201 virtual size_t GetFormatCount() const;
202 virtual wxDataFormat GetFormat(size_t n) const;
203 };
204
205 //-------------------------------------------------------------------------
206 // wxDropSource
207 //-------------------------------------------------------------------------
208
209 class wxDropSource: public wxObject
210 {
211 public:
212
213 enum DragResult
214 {
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)
220 };
221
222 wxDropSource( wxWindow *win );
223 wxDropSource( wxDataObject &data, wxWindow *win );
224
225 ~wxDropSource(void);
226
227 void SetData( wxDataObject &data );
228 DragResult DoDragDrop( bool bAllowMove = FALSE );
229
230 virtual bool GiveFeedback( DragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; };
231
232 protected:
233
234 wxDataObject *m_data;
235 };
236
237 #endif
238 //__GTKDNDH__
239